当前位置: 首页>>代码示例>>Python>>正文


Python synchronize.Event方法代码示例

本文整理汇总了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,
    ) 
开发者ID:pgjones,项目名称:hypercorn,代码行数:19,代码来源:run.py

示例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,
    ) 
开发者ID:pgjones,项目名称:hypercorn,代码行数:23,代码来源:run.py

示例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() 
开发者ID:fetchai,项目名称:agents-aea,代码行数:26,代码来源:launcher.py

示例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() 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:__init__.py

示例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) 
开发者ID:pgjones,项目名称:hypercorn,代码行数:9,代码来源:utils.py

示例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)) 
开发者ID:pgjones,项目名称:hypercorn,代码行数:17,代码来源:run.py

示例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__() 
开发者ID:fetchai,项目名称:agents-aea,代码行数:12,代码来源:launcher.py

示例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() 
开发者ID:joblib,项目名称:loky,代码行数:6,代码来源:context.py

示例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() 
开发者ID:renskiy,项目名称:fabricio,代码行数:9,代码来源:test_postgres.py


注:本文中的multiprocessing.synchronize.Event方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。