本文整理匯總了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()