本文整理汇总了Python中multiprocessing.synchronize.Event方法的典型用法代码示例。如果您正苦于以下问题:Python synchronize.Event方法的具体用法?Python synchronize.Event怎么用?Python synchronize.Event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.synchronize
的用法示例。
在下文中一共展示了synchronize.Event方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: asyncio_worker
# 需要导入模块: from multiprocessing import synchronize [as 别名]
# 或者: from multiprocessing.synchronize import Event [as 别名]
def asyncio_worker(
config: Config, sockets: Optional[Sockets] = None, shutdown_event: Optional[EventType] = None
) -> None:
app = load_application(config.application_path)
shutdown_trigger = None
if shutdown_event is not None:
shutdown_trigger = partial(check_multiprocess_shutdown_event, shutdown_event, asyncio.sleep)
if config.workers > 1 and platform.system() == "Windows":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore
_run(
partial(worker_serve, app, config, sockets=sockets),
debug=config.debug,
shutdown_trigger=shutdown_trigger,
)
示例2: uvloop_worker
# 需要导入模块: from multiprocessing import synchronize [as 别名]
# 或者: from multiprocessing.synchronize import Event [as 别名]
def uvloop_worker(
config: Config, sockets: Optional[Sockets] = None, shutdown_event: Optional[EventType] = None
) -> None:
try:
import uvloop
except ImportError as error:
raise Exception("uvloop is not installed") from error
else:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
app = load_application(config.application_path)
shutdown_trigger = None
if shutdown_event is not None:
shutdown_trigger = partial(check_multiprocess_shutdown_event, shutdown_event, asyncio.sleep)
_run(
partial(worker_serve, app, config, sockets=sockets),
debug=config.debug,
shutdown_trigger=shutdown_trigger,
)
示例3: _run_agent
# 需要导入模块: from multiprocessing import synchronize [as 别名]
# 或者: from multiprocessing.synchronize import Event [as 别名]
def _run_agent(agent_dir: Union[PathLike, str], stop_event: Event) -> None:
"""
Load and run agent in a dedicated process.
:param agent_dir: agent configuration directory
:param stop_event: multithreading Event to stop agent run.
:return: None
"""
agent = load_agent(agent_dir)
def stop_event_thread():
stop_event.wait()
agent.stop()
Thread(target=stop_event_thread, daemon=True).start()
try:
agent.start()
except Exception as e:
exc = AEAException(f"Raised {type(e)}({e})")
exc.__traceback__ = e.__traceback__
raise exc
finally:
stop_event.set()
示例4: Event
# 需要导入模块: from multiprocessing import synchronize [as 别名]
# 或者: from multiprocessing.synchronize import Event [as 别名]
def Event():
'''
Returns an event object
'''
from multiprocessing.synchronize import Event
return Event()
示例5: check_multiprocess_shutdown_event
# 需要导入模块: from multiprocessing import synchronize [as 别名]
# 或者: from multiprocessing.synchronize import Event [as 别名]
def check_multiprocess_shutdown_event(
shutdown_event: EventType, sleep: Callable[[float], Awaitable[Any]]
) -> None:
while True:
if shutdown_event.is_set():
return
await sleep(0.1)
示例6: trio_worker
# 需要导入模块: from multiprocessing import synchronize [as 别名]
# 或者: from multiprocessing.synchronize import Event [as 别名]
def trio_worker(
config: Config, sockets: Optional[Sockets] = None, shutdown_event: Optional[EventType] = None
) -> None:
if sockets is not None:
for sock in sockets.secure_sockets:
sock.listen(config.backlog)
for sock in sockets.insecure_sockets:
sock.listen(config.backlog)
app = load_application(config.application_path)
shutdown_trigger = None
if shutdown_event is not None:
shutdown_trigger = partial(check_multiprocess_shutdown_event, shutdown_event, trio.sleep)
trio.run(partial(worker_serve, app, config, sockets=sockets, shutdown_trigger=shutdown_trigger))
示例7: __init__
# 需要导入模块: from multiprocessing import synchronize [as 别名]
# 或者: from multiprocessing.synchronize import Event [as 别名]
def __init__(self, agent_dir: Union[PathLike, str]):
"""
Init aea config dir task.
:param agent_dir: direcory with aea config.
"""
self._agent_dir = agent_dir
self._manager = multiprocessing.Manager()
self._stop_event = self._manager.Event()
super().__init__()
示例8: Event
# 需要导入模块: from multiprocessing import synchronize [as 别名]
# 或者: from multiprocessing.synchronize import Event [as 别名]
def Event(self):
"""Returns an event object"""
from .synchronize import Event
return Event()
示例9: setUp
# 需要导入模块: from multiprocessing import synchronize [as 别名]
# 或者: from multiprocessing.synchronize import Event [as 别名]
def setUp(self):
self.fab_settings = fab.settings(fab.hide('everything'))
self.fab_settings.__enter__()
self.event_wait_mock = mock.patch.object(Event, 'wait')
self.event_wait_mock.start()
self.stderr = sys.stderr
sys.stderr = six.BytesIO()