當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。