Python asyncio.ProactorEventLoop() Examples

The following are 30 code examples of asyncio.ProactorEventLoop(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module asyncio , or try the search function .
Example #1
Source File: vlcscheduler.py    From VLC-Scheduler with MIT License 8 votes vote down vote up
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.') 
Example #2
Source File: base_proxy.py    From aiohttp-socks with Apache License 2.0 7 votes vote down vote up
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() 
Example #3
Source File: genesis.py    From GenesisZ with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #4
Source File: core.py    From LedFx with MIT License 6 votes vote down vote up
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 
Example #5
Source File: utils.py    From gita with MIT License 6 votes vote down vote up
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 
Example #6
Source File: test_proactor_events.py    From android_universal with MIT License 5 votes vote down vote up
def setUp(self):
        self.loop = asyncio.ProactorEventLoop()
        self.set_event_loop(self.loop)
        self.addCleanup(self.loop.close)
        self.file = open(support.TESTFN, 'rb')
        self.addCleanup(self.file.close)
        super().setUp() 
Example #7
Source File: test_server.py    From android_universal with MIT License 5 votes vote down vote up
def new_loop(self):
        return asyncio.ProactorEventLoop() 
Example #8
Source File: subprocess.py    From colcon-core with Apache License 2.0 5 votes vote down vote up
def new_event_loop():
    """
    Create a new event loop.

    On Windows return a ProactorEventLoop.

    :returns: The created event loop
    """
    if sys.platform == 'win32':
        return asyncio.ProactorEventLoop()
    return asyncio.new_event_loop() 
Example #9
Source File: test_subprocess.py    From pytest-asyncio with Apache License 2.0 5 votes vote down vote up
def event_loop():
        loop = asyncio.ProactorEventLoop()
        yield loop
        loop.close() 
Example #10
Source File: test_windows_events.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        self.loop = asyncio.ProactorEventLoop()
        self.set_event_loop(self.loop) 
Example #11
Source File: test_events.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def create_event_loop(self):
            return asyncio.ProactorEventLoop() 
Example #12
Source File: test_subprocess.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
            super().setUp()
            self.loop = asyncio.ProactorEventLoop()
            self.set_event_loop(self.loop) 
Example #13
Source File: test_subprocess.py    From android_universal with MIT License 5 votes vote down vote up
def setUp(self):
            super().setUp()
            self.loop = asyncio.ProactorEventLoop()
            self.set_event_loop(self.loop) 
Example #14
Source File: pluginManager.py    From BotHub with Apache License 2.0 5 votes vote down vote up
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) 
Example #15
Source File: test_windows_events.py    From annotated-py-projects with MIT License 5 votes vote down vote up
def setUp(self):
        self.loop = asyncio.ProactorEventLoop()
        self.set_event_loop(self.loop) 
Example #16
Source File: test_events.py    From annotated-py-projects with MIT License 5 votes vote down vote up
def create_event_loop(self):
            return asyncio.ProactorEventLoop() 
Example #17
Source File: discordRichPresencePlex.py    From discord-rich-presence-plex with MIT License 5 votes vote down vote up
def start(self):
		self.child.log("Opening Discord IPC Pipe")
		emptyProcessFilePath = tempfile.gettempdir() + ("/" if isLinux else "\\") + "discordRichPresencePlex-emptyProcess.py"
		if (not os.path.exists(emptyProcessFilePath)):
			with open(emptyProcessFilePath, "w") as emptyProcessFile:
				emptyProcessFile.write("import time\n\ntry:\n\twhile (True):\n\t\ttime.sleep(3600)\nexcept:\n\tpass")
		self.process = subprocess.Popen(["python3" if isLinux else "pythonw", emptyProcessFilePath])
		self.loop = asyncio.new_event_loop() if isLinux else asyncio.ProactorEventLoop()
		self.loop.run_until_complete(self.handshake()) 
Example #18
Source File: subprocess_shell.py    From annotated-py-projects with MIT License 5 votes vote down vote up
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() 
Example #19
Source File: test_subprocess.py    From annotated-py-projects with MIT License 5 votes vote down vote up
def setUp(self):
            self.loop = asyncio.ProactorEventLoop()
            self.set_event_loop(self.loop) 
Example #20
Source File: baseclient.py    From pypresence with MIT License 5 votes vote down vote up
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() 
Example #21
Source File: pluginManager.py    From TG-UserBot with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #22
Source File: async_run.py    From slim with zlib License 5 votes vote down vote up
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 
Example #23
Source File: test_windows_events.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.loop = asyncio.ProactorEventLoop()
        self.set_event_loop(self.loop) 
Example #24
Source File: test_events.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def create_event_loop(self):
            return asyncio.ProactorEventLoop() 
Example #25
Source File: test_subprocess.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def setUp(self):
            self.loop = asyncio.ProactorEventLoop()
            self.set_event_loop(self.loop) 
Example #26
Source File: test_windows_events.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        self.loop = asyncio.ProactorEventLoop()
        self.set_event_loop(self.loop) 
Example #27
Source File: test_events.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def create_event_loop(self):
            return asyncio.ProactorEventLoop() 
Example #28
Source File: test_subprocess.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
            self.loop = asyncio.ProactorEventLoop()
            self.set_event_loop(self.loop) 
Example #29
Source File: util.py    From distex with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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() 
Example #30
Source File: utils.py    From bob with GNU General Public License v3.0 5 votes vote down vote up
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