def test_daemonize_pid_null_one(self): with mock.patch('os.fork', side_effect=fork_fake): with mock.patch('os.setsid', mock.Mock()): with mock.patch('os._exit', self.exit_mock): daemonize() self.assertEqual(1, self.exit_mock.call_count) self.exit_mock.assert_called_once_with(0)
def test_daemonize_pid_null(self): pid = 0 with mock.patch('os.fork', mock.Mock(return_value=pid)): with mock.patch('os.setsid', mock.Mock()): with mock.patch('os._exit', self.exit_mock): daemonize() self.assertEqual(0, self.exit_mock.call_count)
def run(self): self._init_env() self._save_main_pid() print 'monitor initiallizing...' time.sleep(2) utils.daemonize(stdin='/dev/null', stdout='/tmp/monitor.log', stderr='/tmp/monitor.log') self._init_all_process() self._check_loop()
def test_daemonize(self): pid = 13 with mock.patch("os.fork", mock.Mock(return_value=pid)) as mock_os_fork: with mock.patch("os._exit", mock.Mock()) as mock_os_exit: utils.daemonize() mock_os_fork.assert_called_once_with() mock_os_exit.assert_called_once_with(0)
def test_daemonize_pid_zero(self): pid = 0 with mock.patch("os.fork", mock.Mock(return_value=pid)) as mock_os_fork: with mock.patch("os.setsid", mock.Mock()) as mock_os_setsid: utils.daemonize() mock_os_setsid.assert_called_once_with() self.assertTrue(mock_os_fork.call_count == 2)
def test_daemonize_pid_zero_not_zero(self): pid = 13 with mock.patch("os.fork", mock.Mock(side_effect=[0, pid])) as mock_os_fork: with mock.patch("os.setsid", mock.Mock()) as mock_os_setsid: with mock.patch("os._exit", mock.Mock()) as mock_os_exit: utils.daemonize() mock_os_setsid.assert_called_once_with() mock_os_exit.assert_called_once_with(0) self.assertTrue(mock_os_fork.call_count == 2)
def main(argv): args = parse_cmd_args(argv[1:]) if args.daemon: daemonize() if args.pidfile: create_pidfile(args.pidfile) config = _load_config(args) dictConfig(config.LOGGING) main_loop(config) return config.EXIT_CODE
def main(argv): args = parse_cmd_args(argv[1:]) if args.daemon: daemonize() if args.pidfile: create_pidfile(args.pidfile) config = load_config_from_pyfile( os.path.realpath(os.path.expanduser(args.config))) dictConfig(config.LOGGING) main_loop(config) return config.EXIT_CODE
def main(argv): args = parse_cmd_args(argv[1:]) if args.daemon: daemonize() if args.pidfile: create_pidfile(args.pidfile) config = load_config_from_pyfile( os.path.realpath(os.path.expanduser(args.config)) ) dictConfig(config.LOGGING) main_loop(config) return config.EXIT_CODE
def main(argv): """ Точка входа в приложение. В случае возникновения ошибки в приложении, оно засыпает на config.SLEEP_ON_FAIL секунд. :param argv: агрументы командной строки. :type argv: list """ args = parse_cmd_args(argv[1:]) if args.daemon: daemonize() if args.pidfile: create_pidfile(args.pidfile) config = load_config_from_pyfile( os.path.realpath(os.path.expanduser(args.config)) ) patch_all() dictConfig(config.LOGGING) current_thread().name = 'pusher.main' install_signal_handlers() while run_application: try: main_loop(config) except Exception as exc: logger.error( 'Error in main loop. Go to sleep on {} second(s).'.format(config.SLEEP_ON_FAIL) ) logger.exception(exc) sleep(config.SLEEP_ON_FAIL) else: logger.info('Stop application loop in main.') return exit_code
def test_daemonize_nonzero_pid(self): with patch('os.fork', Mock(return_value=10)): with patch('os._exit', Mock()): utils.daemonize()
def test_daemonize_zero_pid2(self): with patch('os.fork', Mock(side_effect=[0, -1])): with patch('os.setsid', Mock()): with patch('os._exit', Mock()): utils.daemonize()
def test_daemonize_zero_pid1(self): with patch('os.fork', Mock(side_effect=[0, 1])): with patch('os.setsid', Mock()): with patch('os._exit', Mock()): utils.daemonize()
def test_daemonize_pid_not_null(self): pid = 1 with mock.patch('os.fork', mock.Mock(return_value=pid)): with mock.patch('os._exit', self.exit_mock): daemonize() self.exit_mock.assert_called_once_with(0)