本文整理匯總了Python中oslo_service.service.ProcessLauncher方法的典型用法代碼示例。如果您正苦於以下問題:Python service.ProcessLauncher方法的具體用法?Python service.ProcessLauncher怎麽用?Python service.ProcessLauncher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oslo_service.service
的用法示例。
在下文中一共展示了service.ProcessLauncher方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_parent_process_reload_config
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def test_parent_process_reload_config(self,
is_sighup_and_daemon_mock,
reload_config_files_mock,
notify_once_mock,
log_opt_values_mock,
handle_signal_mock,
respawn_children_mock,
stop_mock,
kill_mock,
alarm_mock):
is_sighup_and_daemon_mock.return_value = True
respawn_children_mock.side_effect = [None,
eventlet.greenlet.GreenletExit()]
launcher = service.ProcessLauncher(self.conf)
launcher.sigcaught = 1
launcher.children = {}
wrap_mock = mock.Mock()
launcher.children[222] = wrap_mock
launcher.wait()
reload_config_files_mock.assert_called_once_with()
wrap_mock.service.reset.assert_called_once_with()
示例2: start
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def start(self, application, port, host='0.0.0.0', workers=0):
"""Run a WSGI server with the given application."""
self._host = host
self._port = port
backlog = CONF.backlog
self._socket = self._get_socket(self._host,
self._port,
backlog=backlog)
if workers < 1:
# For the case where only one process is required.
self._server = self.pool.spawn(self._run, application,
self._socket)
systemd.notify_once()
else:
# Minimize the cost of checking for child exit by extending the
# wait interval past the default of 0.01s.
self._launcher = common_service.ProcessLauncher(
CONF, wait_interval=1.0, restart_method='mutate')
self._server = WorkerService(self, application)
self._launcher.launch_service(self._server, workers=workers)
示例3: process_launcher
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def process_launcher():
return service.ProcessLauncher(CONF, restart_method='mutate')
示例4: main
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def main():
service.prepare_service()
launcher = os_service.ProcessLauncher(CONF, restart_method='mutate')
launcher.launch_service(
listener.ListenerService(),
workers=CONF.listener.workers)
launcher.wait()
示例5: process_launcher
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def process_launcher():
return service.ProcessLauncher(CONF, restart_method='mutate')
# NOTE(vish): the global launcher is to maintain the existing
# functionality of calling service.serve +
# service.wait
示例6: process_launcher
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def process_launcher():
return service.ProcessLauncher(CONF, restart_method='mutate')
# NOTE: the global launcher is to maintain the existing
# functionality of calling service.serve +
# service.wait
示例7: test_mutate_hook_process_launcher
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def test_mutate_hook_process_launcher(self):
"""Test mutate_config_files is called by ProcessLauncher on SIGHUP.
Forks happen in _spawn_service and ProcessLauncher. So we get three
tiers of processes, the top tier being the test process. self.pid
refers to the middle tier, which represents our application. Both
service_maker and launcher_maker execute in the middle tier. The bottom
tier is the workers.
The behavior we want is that when the application (middle tier)
receives a SIGHUP, it catches that, calls mutate_config_files and
relaunches all the workers. This causes them to inherit the mutated
config.
"""
mutate = multiprocessing.Event()
ready = multiprocessing.Event()
def service_maker():
self.conf.register_mutate_hook(lambda c, f: mutate.set())
return ServiceWithTimer(ready)
def launcher_maker():
return service.ProcessLauncher(self.conf, restart_method='mutate')
self.pid = self._spawn_service(1, service_maker, launcher_maker)
timeout = 5
ready.wait(timeout)
self.assertTrue(ready.is_set(), 'Service never became ready')
ready.clear()
self.assertFalse(mutate.is_set(), "Hook was called too early")
os.kill(self.pid, signal.SIGHUP)
ready.wait(timeout)
self.assertTrue(ready.is_set(), 'Service never back after SIGHUP')
self.assertTrue(mutate.is_set(), "Hook wasn't called")
示例8: test_stop
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def test_stop(self, signal_mock, alarm_mock):
signal_mock.SIGTERM = 15
launcher = service.ProcessLauncher(self.conf)
self.assertTrue(launcher.running)
pid_nums = [22, 222]
fakeServiceWrapper = service.ServiceWrapper(service.Service(), 1)
launcher.children = {pid_nums[0]: fakeServiceWrapper,
pid_nums[1]: fakeServiceWrapper}
with mock.patch('oslo_service.service.os.kill') as mock_kill:
with mock.patch.object(launcher, '_wait_child') as _wait_child:
def fake_wait_child():
pid = pid_nums.pop()
return launcher.children.pop(pid)
_wait_child.side_effect = fake_wait_child
with mock.patch('oslo_service.service.Service.stop') as \
mock_service_stop:
mock_service_stop.side_effect = lambda: None
launcher.stop()
self.assertFalse(launcher.running)
self.assertFalse(launcher.children)
mock_kill.assert_has_calls([mock.call(222, signal_mock.SIGTERM),
mock.call(22, signal_mock.SIGTERM)],
any_order=True)
self.assertEqual(2, mock_kill.call_count)
mock_service_stop.assert_called_once_with()
示例9: test_check_service_base
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def test_check_service_base(self, pipe_mock, green_pipe_mock,
handle_signal_mock, start_child_mock):
pipe_mock.return_value = [None, None]
launcher = service.ProcessLauncher(self.conf)
serv = _Service()
launcher.launch_service(serv, workers=0)
示例10: test_check_service_base_fails
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def test_check_service_base_fails(self, pipe_mock, green_pipe_mock,
handle_signal_mock, start_child_mock):
pipe_mock.return_value = [None, None]
launcher = service.ProcessLauncher(self.conf)
class FooService(object):
def __init__(self):
pass
serv = FooService()
self.assertRaises(TypeError, launcher.launch_service, serv, 0)
示例11: process_launcher
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def process_launcher():
return service.ProcessLauncher(CONF)
# NOTE(vish): the global launcher is to maintain the existing
# functionality of calling service.serve +
# service.wait
示例12: get_launcher
# 需要導入模塊: from oslo_service import service [as 別名]
# 或者: from oslo_service.service import ProcessLauncher [as 別名]
def get_launcher():
# Note(lpetrut): ProcessLauncher uses green pipes which fail on Windows
# due to missing support of non-blocking I/O pipes. For this reason, the
# service must be spawned differently on Windows, using the ServiceLauncher
# class instead.
if os.name == 'nt':
return Launcher()
else:
return process_launcher()