當前位置: 首頁>>代碼示例>>Python>>正文


Python asyncio.ProactorEventLoop方法代碼示例

本文整理匯總了Python中asyncio.ProactorEventLoop方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.ProactorEventLoop方法的具體用法?Python asyncio.ProactorEventLoop怎麽用?Python asyncio.ProactorEventLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在asyncio的用法示例。


在下文中一共展示了asyncio.ProactorEventLoop方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def main():
    logger.info('VLC Scheduler v%s started.' % version.VERSION)
    
    if sys.platform == 'win32':
        loop = asyncio.ProactorEventLoop()
        asyncio.set_event_loop(loop)
    
    loop = asyncio.get_event_loop()
    
    try:
        loop.run_until_complete(main_coro())
    except Exception as e:
        if config.DEBUG:
            logger.fatal(traceback.format_exc())
        else:
            logger.fatal(str(e))
    finally:
        loop.close()
        logger.info('VLC Scheduler stopped.') 
開發者ID:EugeneDae,項目名稱:VLC-Scheduler,代碼行數:21,代碼來源:vlcscheduler.py

示例2: _can_be_closed_safely

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def _can_be_closed_safely(self):  # pragma: no cover
        def is_proactor_event_loop():
            try:
                from asyncio import ProactorEventLoop
            except ImportError:
                return False
            return isinstance(self._loop, ProactorEventLoop)

        def is_uvloop_event_loop():
            try:
                # noinspection PyPackageRequirements
                from uvloop import Loop
            except ImportError:
                return False
            return isinstance(self._loop, Loop)

        return is_proactor_event_loop() or is_uvloop_event_loop() 
開發者ID:romis2012,項目名稱:aiohttp-socks,代碼行數:19,代碼來源:base_proxy.py

示例3: __init__

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def __init__(self, config_dir):
        self.config_dir = config_dir
        self.config = load_config(config_dir)

        if sys.platform == 'win32':
            self.loop = asyncio.ProactorEventLoop()
        else:
            self.loop = asyncio.get_event_loop()
        executor_opts = {'max_workers': self.config.get('max_workers')}

        self.executor = ThreadPoolExecutor(**executor_opts)
        self.loop.set_default_executor(self.executor)
        self.loop.set_exception_handler(self.loop_exception_handler)

        self.events = Events(self)
        self.http = HttpServer(
            ledfx=self, host=self.config['host'], port=self.config['port'])
        self.exit_code = None 
開發者ID:ahodges9,項目名稱:LedFx,代碼行數:20,代碼來源:core.py

示例4: exec_async_tasks

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def exec_async_tasks(tasks: List[Coroutine]) -> List[Union[None, str]]:
    """
    Execute tasks asynchronously
    """
    # TODO: asyncio API is nicer in python 3.7
    if platform.system() == 'Windows':
        loop = asyncio.ProactorEventLoop()
        asyncio.set_event_loop(loop)
    else:
        loop = asyncio.get_event_loop()

    try:
        errors = loop.run_until_complete(asyncio.gather(*tasks))
    finally:
        loop.close()
    return errors 
開發者ID:nosarthur,項目名稱:gita,代碼行數:18,代碼來源:utils.py

示例5: main

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def main():
    args = parse_args()

    eh = build_EquihashInputHeader(args)
    if args.solver_type == 'tromp':
        solver = TrompSolver(args.solver, eh, args.rounds, args.nonce, args.threads)
    elif args.solver_type == 'silentarmy':
        solver = SilentarmySolver(args.solver, eh, args.rounds, args.nonce)

    # as if I cared about windows users...
    if sys.platform == "win32":
        loop = asyncio.ProactorEventLoop()
        asyncio.set_event_loop(loop)
    else:
        loop = asyncio.get_event_loop()

    try:
        solution, nonce = loop.run_until_complete(solver.run())
        h = CZBlockHeader.from_EquihashHeader(eh, solution, nonce)
        print('Solution found!\nHeader Hash: {}\nNonce: {}\n{}'
                .format(b2lx(h.GetHash()), b2lx(nonce), b2x(solution)))
    except SolverException as e:
        warn('{}\nExiting.'.format(e))
    finally:
        loop.close() 
開發者ID:sebastianst,項目名稱:GenesisZ,代碼行數:27,代碼來源:genesis.py

示例6: __init__

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def __init__(self):
        import asyncio
        import multiprocessing
        import signal
        import concurrent.futures

        if sys.platform == 'win32':
            loop = asyncio.ProactorEventLoop()
            asyncio.set_event_loop(loop)
            multiprocessing.set_start_method('spawn')
            executor = concurrent.futures.ProcessPoolExecutor()
        else:
            # The ProcessPoolExecutor is a barely usable for our interactive use
            # case. On SIGINT any busy executor should stop. The only way how this
            # does not explode is that we ignore SIGINT before spawning the process
            # pool and re-enable SIGINT in every executor. In the main process we
            # have to ignore BrokenProcessPool errors as we will likely hit them.
            # To "prime" the process pool a dummy workload must be executed because
            # the processes are spawned lazily.
            loop = asyncio.get_event_loop()
            origSigInt = signal.getsignal(signal.SIGINT)
            signal.signal(signal.SIGINT, signal.SIG_IGN)
            # fork early before process gets big
            if sys.platform == 'msys':
                multiprocessing.set_start_method('fork')
            else:
                multiprocessing.set_start_method('forkserver')
            executor = concurrent.futures.ProcessPoolExecutor()
            executor.submit(dummy).result()
            signal.signal(signal.SIGINT, origSigInt)
        loop.set_default_executor(executor)

        self.__loop = loop
        self.__executor = executor 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:36,代碼來源:utils.py

示例7: get_loop

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def get_loop():
    """
    Get optimal event loop for the platform.
    """
    loop = None
    if sys.platform == 'win32':
        loop = asyncio.ProactorEventLoop()
    else:
        with suppress(ImportError):
            import uvloop
            loop = uvloop.Loop()
    return loop or asyncio.get_event_loop() 
開發者ID:erdewit,項目名稱:distex,代碼行數:14,代碼來源:util.py

示例8: setUp

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def setUp(self):
            self.loop = asyncio.ProactorEventLoop()
            self.set_event_loop(self.loop) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:5,代碼來源:test_subprocess.py

示例9: create_event_loop

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def create_event_loop(self):
            return asyncio.ProactorEventLoop() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:4,代碼來源:test_events.py

示例10: setUp

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def setUp(self):
        self.loop = asyncio.ProactorEventLoop()
        self.set_event_loop(self.loop) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:5,代碼來源:test_windows_events.py

示例11: get_ioloop

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def get_ioloop() -> asyncio.BaseEventLoop:
    loop = asyncio.get_event_loop()
    if sys.platform == 'win32' and not isinstance(loop, asyncio.ProactorEventLoop):
        loop = asyncio.ProactorEventLoop()
        ctlc_hotfix(loop)
        asyncio.set_event_loop(loop)
    return loop 
開發者ID:fy0,項目名稱:slim,代碼行數:9,代碼來源:async_run.py

示例12: run_async

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def run_async(func: callable):
    """Run async functions with the right event loop."""
    if sys.platform.startswith('win'):
        loop = asyncio.ProactorEventLoop()
    else:
        loop = asyncio.get_event_loop()
    return loop.run_until_complete(func) 
開發者ID:TG-UserBot,項目名稱:TG-UserBot,代碼行數:9,代碼來源:pluginManager.py

示例13: get_event_loop

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def get_event_loop(self, force_fresh=False):
        if sys.platform == 'linux' or sys.platform == 'darwin':
            if force_fresh:
                return asyncio.new_event_loop()
            loop = asyncio.get_event_loop()
            if loop.is_closed():
                return asyncio.new_event_loop()
            return loop
        elif sys.platform == 'win32':
            if force_fresh:
                return asyncio.ProactorEventLoop()
            loop = asyncio.get_event_loop()
            if isinstance(loop, asyncio.ProactorEventLoop) and not loop.is_closed():
                return loop
            return asyncio.ProactorEventLoop() 
開發者ID:qwertyquerty,項目名稱:pypresence,代碼行數:17,代碼來源:baseclient.py

示例14: main

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def main():
    if os.name == 'nt':
        loop = asyncio.ProactorEventLoop()
        asyncio.set_event_loop(loop)
    else:
        loop = asyncio.get_event_loop()
    loop.run_until_complete(start(
        'sleep 2; wc', input=[b'foo bar baz\n'*300 for i in range(100)]))
    loop.close() 
開發者ID:hhstore,項目名稱:annotated-py-projects,代碼行數:11,代碼來源:subprocess_shell.py

示例15: setUp

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import ProactorEventLoop [as 別名]
def setUp(self):
            super().setUp()
            self.loop = asyncio.ProactorEventLoop()
            self.set_event_loop(self.loop) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:6,代碼來源:test_subprocess.py


注:本文中的asyncio.ProactorEventLoop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。