本文整理汇总了Python中circus.watcher.Watcher.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Watcher.stop方法的具体用法?Python Watcher.stop怎么用?Python Watcher.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类circus.watcher.Watcher
的用法示例。
在下文中一共展示了Watcher.stop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SomeWatcher
# 需要导入模块: from circus.watcher import Watcher [as 别名]
# 或者: from circus.watcher.Watcher import stop [as 别名]
class SomeWatcher(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.stream = QueueStream()
self.loop = self.watcher = None
def run(self):
qstream = {'stream': self.stream}
old_environ = os.environ
old_paths = sys.path[:]
try:
sys.path = ['XYZ']
os.environ = {'COCONUTS': 'MIGRATE'}
cmd = ('%s -c "import sys; '
'sys.stdout.write(\':\'.join(sys.path)); '
' sys.stdout.flush()"') % sys.executable
self.loop = ioloop.IOLoop.instance()
self.watcher = Watcher('xx', cmd, copy_env=True, copy_path=True,
stdout_stream=qstream, loop=self.loop)
self.watcher.start()
self.loop.start()
finally:
os.environ = old_environ
sys.path[:] = old_paths
def stop(self):
if self.loop is not None:
self.loop.stop()
if self.watcher is not None:
self.watcher.stop()
self.join()
示例2: test_stopping_a_watcher_doesnt_spawn
# 需要导入模块: from circus.watcher import Watcher [as 别名]
# 或者: from circus.watcher.Watcher import stop [as 别名]
def test_stopping_a_watcher_doesnt_spawn(self):
watcher = Watcher("foo", "foobar", respawn=True, numprocesses=3)
watcher.stopped = False
watcher.spawn_processes = mock.MagicMock()
watcher.loop = mock.MagicMock()
watcher.send_signal = mock.MagicMock()
# We have one running process and a dead one.
watcher.processes = {1234: FakeProcess(1234, status=RUNNING),
1235: FakeProcess(1235, status=RUNNING)}
# When we call manage_process(), the watcher should try to spawn a new
# process since we aim to have 3 of them.
watcher.manage_processes()
self.assertTrue(watcher.spawn_processes.called)
# Now, we want to stop everything.
watcher.processes = {1234: FakeProcess(1234, status=RUNNING),
1235: FakeProcess(1235, status=RUNNING)}
watcher.spawn_processes.reset_mock()
watcher.stop()
watcher.manage_processes()
# And be sure we don't spawn new processes in the meantime.
self.assertFalse(watcher.spawn_processes.called)
示例3: SomeWatcher
# 需要导入模块: from circus.watcher import Watcher [as 别名]
# 或者: from circus.watcher.Watcher import stop [as 别名]
class SomeWatcher(threading.Thread):
def __init__(self, **kw):
threading.Thread.__init__(self)
self.stream = QueueStream()
self.loop = self.watcher = None
self.kw = kw
def run(self):
qstream = {"stream": self.stream}
old_environ = os.environ
old_paths = sys.path[:]
try:
sys.path = ["XYZ"]
os.environ = {"COCONUTS": "MIGRATE"}
cmd = (
'%s -c "import sys; ' "sys.stdout.write(':'.join(sys.path)); " ' sys.stdout.flush()"'
) % sys.executable
self.loop = ioloop.IOLoop()
self.watcher = Watcher(
"xx", cmd, copy_env=True, copy_path=True, stdout_stream=qstream, loop=self.loop, **self.kw
)
self.watcher.start()
self.loop.start()
finally:
os.environ = old_environ
sys.path[:] = old_paths
def stop(self):
if self.loop is not None:
self.loop.stop()
if self.watcher is not None:
self.watcher.stop()
self.join()
示例4: SomeWatcher
# 需要导入模块: from circus.watcher import Watcher [as 别名]
# 或者: from circus.watcher.Watcher import stop [as 别名]
class SomeWatcher(object):
def __init__(self, loop=None, **kw):
self.stream = QueueStream()
self.watcher = None
self.kw = kw
if loop is None:
self.loop = tornado.ioloop.IOLoop.instance()
else:
self.loop = loop
@tornado.gen.coroutine
def run(self):
qstream = {'stream': self.stream}
old_environ = os.environ
old_paths = sys.path[:]
try:
sys.path = ['XYZ']
os.environ = {'COCONUTS': 'MIGRATE'}
cmd = ('%s -c "import sys; '
'sys.stdout.write(\':\'.join(sys.path)); '
' sys.stdout.flush()"') % sys.executable
self.watcher = Watcher('xx', cmd, copy_env=True, copy_path=True,
stdout_stream=qstream, loop=self.loop,
**self.kw)
yield self.watcher.start()
finally:
os.environ = old_environ
sys.path[:] = old_paths
@tornado.gen.coroutine
def stop(self):
if self.watcher is not None:
yield self.watcher.stop()
示例5: test_copy_path
# 需要导入模块: from circus.watcher import Watcher [as 别名]
# 或者: from circus.watcher.Watcher import stop [as 别名]
def test_copy_path(self):
stream = QueueStream()
qstream = {'stream': stream}
old_environ = os.environ
old_paths = sys.path[:]
try:
sys.path = ['XYZ']
os.environ = {'COCONUTS': 'MIGRATE'}
cmd = ('%s -c "import sys; '
'sys.stdout.write(\':\'.join(sys.path)); '
' sys.stdout.flush()"') % sys.executable
watcher = Watcher('xx', cmd, copy_env=True, copy_path=True,
stdout_stream=qstream)
watcher.start()
time.sleep(3.)
watcher.stop()
data = [v for k, v in stream.get().items()][1]
data = ''.join(data)
self.assertTrue('XYZ' in data, data)
finally:
os.environ = old_environ
sys.path[:] = old_paths