55+ results for 'python asyncio wait_for' (2566 ms)
17 import zmq.asyncio as zaio 18 from zmq.auth.asyncio import AsyncioAuthenticator 19except ImportError: 21 raise 22 asyncio = None 23 28 29class TestAsyncIOSocket(BaseZMQTestCase): 30 if asyncio is not None: 49 def test_recv_multipart(self): 50 @asyncio.coroutine 51 def test(): 154 f = b.recv_json() 155 recvd = yield from asyncio.wait_for(f, timeout=5) 156 assert recvd == objlegacy.py https://gitlab.com/storedmirrors/qemu | Python | 315 lines
23 24import asyncio 25from types import TracebackType 81 self._qmp = QMPClient(nickname) 82 self._aloop = asyncio.get_event_loop() 83 self._address = address 94 return self._aloop.run_until_complete( 95 asyncio.wait_for(future, timeout=timeout) 96 ) 173 174 :param qmp_cmd: QMP command to be sent as a Python dict 175 :return: QMP response as a Python dict 224 225 :raise asyncio.TimeoutError: 226 When a timeout is requested and the timeout period elapses.timeout.py https://gitlab.com/llndhlov/journly | Python | 127 lines
18 Useful in cases when you want to apply timeout logic around block 19 of code or in cases when asyncio.wait_for is not suitable. For example: 20 37 if loop is None: 38 loop = asyncio.get_event_loop() 39 self._loop = loop 41 self._cancelled = False 42 self._cancel_handler = None # type: Optional[asyncio.Handle] 43 self._cancel_at = None # type: Optional[float] 80 # Support Tornado 5- without timeout 81 # Details: https://github.com/python/asyncio/issues/392 82 if self._timeout is None: 115 116def current_task(loop: asyncio.AbstractEventLoop) -> "Optional[asyncio.Task[Any]]": 117 if sys.version_info >= (3, 7):client.py https://github.com/kergoth/bitbake.git | Python | 172 lines
5import abc 6import asyncio 7import json 25 async def connect_sock(): 26 return await asyncio.open_connection(address, port) 27 31 async def connect_sock(): 32 return await asyncio.open_unix_connection(path) 33 75 try: 76 line = await asyncio.wait_for(self.reader.readline(), self.timeout) 77 except asyncio.TimeoutError: 120 self.client = self._get_async_client() 121 self.loop = asyncio.new_event_loop() 122staggered.py https://gitlab.com/Alioth-Project/clang-r445002 | Python | 149 lines
42 # do work 43 except asyncio.CancelledError: 44 # undo partially completed work 86 with contextlib.suppress(exceptions_mod.TimeoutError): 87 # Use asyncio.wait_for() instead of asyncio.wait() here, so 88 # that if we get cancelled at this point, Event.wait() is also 90 # pending" later. 91 await tasks.wait_for(previous_failed.wait(), delay) 92 # Get the next coroutine to run 123 # up as done() == True, cancelled() == False, exception() == 124 # asyncio.CancelledError. This behavior is specified in 125 # https://bugs.python.org/issue30048asyncio-dev.rst https://gitlab.com/unofficial-mirrors/cpython | ReStructuredText | 418 lines
23* Enable the asyncio debug mode globally by setting the environment variable 24 :envvar:`PYTHONASYNCIODEBUG` to ``1``, or by calling :meth:`AbstractEventLoop.set_debug`. 25* Set the log level of the :ref:`asyncio logger <asyncio-logger>` to 180the execution of the coroutine object will never be scheduled which is 181probably a bug. :ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` 182to :ref:`log a warning <asyncio-logger>` to detect it. 226 loop = asyncio.get_event_loop() 227 asyncio.ensure_future(bug()) 228 loop.run_forever() 243 244:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 245traceback where the task was created. Output in debug mode:: 390 391:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 392traceback where the task was created. Example of log in debug mode:pexpect-4.8.0-py311.patch https://gitlab.com/redcore/portage | Patch | 67 lines
3Date: Thu, 24 Mar 2022 15:15:33 +0100 4Subject: [PATCH] Convert @asyncio.coroutine to async def 5 5 6This is required for Python 3.11+ support. 7 20 21-@asyncio.coroutine 22-def expect_async(expecter, timeout=None): 30 pw.set_expecter(expecter) 31- transport, pw = yield from asyncio.get_event_loop()\ 32+ transport, pw = await asyncio.get_event_loop()\ 39 try: 40- return (yield from asyncio.wait_for(pw.fut, timeout)) 41+ return (await asyncio.wait_for(pw.fut, timeout))tasks.py https://github.com/albertz/CPython.git | Python | 900 lines
5 'FIRST_COMPLETED', 'FIRST_EXCEPTION', 'ALL_COMPLETED', 6 'wait', 'wait_for', 'as_completed', 'sleep', 7 'gather', 'shield', 'ensure_future', 'run_coroutine_threadsafe', 80 81class Task(futures._PyFuture): # Inherit Python Task implementation 82 # from a Python Future implementation. 107 warnings.warn("Task.current_task() is deprecated, " 108 "use asyncio.current_task() instead", 109 PendingDeprecationWarning, 121 warnings.warn("Task.all_tasks() is deprecated, " 122 "use asyncio.all_tasks() instead", 123 PendingDeprecationWarning, 266 else: 267 blocking = getattr(result, '_asyncio_future_blocking', None) 268 if blocking is not None:tasks.py https://gitlab.com/abhi1tb/build | Python | 966 lines
5 'FIRST_COMPLETED', 'FIRST_EXCEPTION', 'ALL_COMPLETED', 6 'wait', 'wait_for', 'as_completed', 'sleep', 7 'gather', 'shield', 'ensure_future', 'run_coroutine_threadsafe', 97 98class Task(futures._PyFuture): # Inherit Python Task implementation 99 # from a Python Future implementation. 123 """ 124 warnings.warn("Task.current_task() is deprecated since Python 3.7, " 125 "use asyncio.current_task() instead", 137 """ 138 warnings.warn("Task.all_tasks() is deprecated since Python 3.7, " 139 "use asyncio.all_tasks() instead", 297 else: 298 blocking = getattr(result, '_asyncio_future_blocking', None) 299 if blocking is not None:locks.py https://gitlab.com/abhi1tb/build | Python | 534 lines
81 82 # The flag is needed for legacy asyncio.iscoroutine() 83 __iter__._is_coroutine = coroutines._is_coroutine 166 self._loop = loop 167 warnings.warn("The loop argument is deprecated since Python 3.8, " 168 "and scheduled for removal in Python 3.10.", 262 self._loop = loop 263 warnings.warn("The loop argument is deprecated since Python 3.8, " 264 "and scheduled for removal in Python 3.10.", 329 self._loop = loop 330 warnings.warn("The loop argument is deprecated since Python 3.8, " 331 "and scheduled for removal in Python 3.10.", 390 391 async def wait_for(self, predicate): 392 """Wait until a predicate becomes true.builtin.py https://gitlab.com/xZwop/PCBOT | Python | 434 lines
117def do(client: discord.Client, message: discord.Message, python_code: Annotate.Code): 118 """ Execute python code. Coroutines do not work, although you can run `say(msg, c=message.channel)` 119 to send a message, optionally to a channel. Eg: `say("Hello!")`. """ 120 def say(msg, m=message): 121 asyncio.async(client.say(m, msg)) 122 125 try: 126 exec(python_code, code_globals) 127 except Exception as e: 133def eval_(client: discord.Client, message: discord.Message, python_code: Annotate.Code): 134 """ Evaluate a python expression. Can be any python code on one line that returns something. """ 135 code_globals.update(dict(message=message, client=client)) 386 random=random, 387 asyncio=asyncio, 388 plugins=pluginssecurity.py https://github.com/gsliepen/tinc.git | Python | 130 lines
1#!/usr/bin/env python3 2 4 5import asyncio 6import typing as T 16 17async def recv(read: asyncio.StreamReader, out: T.List[bytes]) -> None: 18 """Receive data until connection is closed.""" 26 raw = f"{buf}\n".encode("utf-8") 27 read, write = await asyncio.open_connection(host="localhost", port=port) 28 29 if delay: 30 await asyncio.sleep(delay) 31 34 write.write(raw) 35 await asyncio.wait_for(recv(read, received), timeout=1) 36 except asyncio.TimeoutError:engine.py https://gitlab.com/pineiden/collector | Python | 1356 lines
1# stdlilb python 2import asyncio 14import traceback 15from asyncio import shield, wait_for 16from datetime import timedelta, datetimegn_socket.py https://gitlab.com/pineiden/gus | Python | 969 lines
12from basic_logtools.filelog import LogFile 13from asyncio import shield, wait_for, Task 14# These values are constant 55 56# Asyncio guide: 57# http://www.snarky.ca/how-the-heck-does-async-await-work-in-python-3-5 134 self.msg_r = '' 135 # asyncio coroutines 136 self.alert = "" 146 # the idc value to heart_beat assigned to this client 147 self.new_client_queue = asyncio.Queue() 148 # 353 await shield(self.send_text('<END>', writer)) 354 except asyncio.CancelledError as ex: 355 bprint("Cancelled error en send_msg")protocol.py https://github.com/chromium/chromium.git | Python | 1291 lines
64 65class WebSocketCommonProtocol(asyncio.Protocol): 66 """ 121 122 To apply a timeout to any other API, wrap it in :func:`~asyncio.wait_for`. 123 136 stops processing incoming data until :meth:`recv` is called. In this 137 situation, various receive buffers (at least in ``asyncio`` and in the OS) 138 will fill up, then the TCP receive window will shrink, slowing down 232 self._paused = False 233 self._drain_waiter: Optional[asyncio.Future[None]] = None 234 288 289 # Copied from asyncio.FlowControlMixin 290 async def _drain_helper(self) -> None: # pragma: no coverelectrumx_rpc.py https://bitbucket.org/arfonzo/electrumx4egc.git | Python | 93 lines
1#!/usr/bin/env python3 2# 13import argparse 14import asyncio 15import json 29 30 async def wait_for_response(self): 31 await self.items_event.wait() 50def rpc_send_and_wait(port, method, params, timeout=15): 51 loop = asyncio.get_event_loop() 52 coro = loop.create_connection(RPCClient, 'localhost', port) 57 coro = rpc_client.wait_for_response() 58 loop.run_until_complete(asyncio.wait_for(coro, timeout)) 59 except asyncio.TimeoutError:asyncio-dev.rst https://bitbucket.org/mirror/cpython/ | ReStructuredText | 411 lines
23* Enable the asyncio debug mode globally by setting the environment variable 24 :envvar:`PYTHONASYNCIODEBUG` to ``1``, or by calling :meth:`AbstractEventLoop.set_debug`. 25* Set the log level of the :ref:`asyncio logger <asyncio-logger>` to 172the execution of the coroutine object will never be scheduled which is 173probably a bug. :ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` 174to :ref:`log a warning <asyncio-logger>` to detect it. 227 Traceback (most recent call last): 228 File "asyncio/tasks.py", line 237, in _step 229 result = next(coro) 235 236:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 237traceback where the task was created. Output in debug mode:: 382 383:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 384traceback where the task was created. Example of log in debug mode:pydevd_concurrency_logger.py https://gitlab.com/ZoZworc/install | Python | 343 lines
35try: 36 import asyncio # @UnresolvedImport 37except: 51 if curFrame.f_code is None: 52 break #Iron Python sometimes does not have it! 53 55 if myName is None: 56 break #Iron Python sometimes does not have it! 57 163 if back_base in INNER_FILES and \ 164 back.f_code.co_name == "_wait_for_tstate_lock": 165 back = back.f_back.f_back 196 send_massage = False 197 # we can't detect stop after join in Python 2 yet 198 if send_massage:clocks.py https://github.com/encukou/gillcup.git | Python | 346 lines
1"""Asyncio-based discrete-time simulation infrastructure 2 4 5If you are familiar with the :mod:`asyncio` library, 6you might know the :func:`asyncio.sleep` coroutine. 8usually based on the computer's system time. 9Since the Python process does not control this time, ``sleep()`` may sleep 10longer than requested if the event loop is busy. 28 29The Clock runs inside an asyncio event loop, 30using the future, callback, and coroutine mechanisms familiar to asyncio users. 50import heapq 51import asyncio 52 60 61 Direct equivalent of :func:`asyncio.coroutine` -- also does nothing 62 (unless asyncio debugging is enabled)._asyncio_backend.py git://github.com/rthalley/dnspython.git | Python | 149 lines
16 try: 17 return asyncio.get_running_loop() 18 except AttributeError: # pragma: no cover 18 except AttributeError: # pragma: no cover 19 return asyncio.get_event_loop() 20 49 try: 50 return await asyncio.wait_for(awaitable, timeout) 51 except asyncio.TimeoutError: 63 async def sendto(self, what, destination, timeout): # pragma: no cover 64 # no timeout for asyncio sendto 65 self.transport.sendto(what, destination) 71 self.protocol.recvfrom = done 72 await _maybe_wait_for(done, timeout) 73 return done.result()pydevd_concurrency_logger.py git://github.com/JetBrains/intellij-community.git | Python | 358 lines
4from _pydevd_bundle.pydevd_constants import get_thread_id, IS_PY3K, IS_PY36_OR_GREATER 5from pydevd_concurrency_analyser.pydevd_thread_wrappers import ObjectWrapper, AsyncioTaskWrapper, wrap_attr 6 37try: 38 import asyncio # @UnresolvedImport 39except: 53 if curFrame.f_code is None: 54 break #Iron Python sometimes does not have it! 55 57 if myName is None: 58 break #Iron Python sometimes does not have it! 59 166 if back_base in INNER_FILES and \ 167 back.f_code.co_name == "_wait_for_tstate_lock": 168 back = back.f_back.f_backasyncio-dev.rst https://bitbucket.org/tpn/pyparallel | ReStructuredText | 397 lines
23* Enable the asyncio debug mode globally by setting the environment variable 24 :envvar:`PYTHONASYNCIODEBUG` to ``1`` 25* Set the log level of the :ref:`asyncio logger <asyncio-logger>` to 166the execution of the coroutine object will never be scheduled which is 167probably a bug. :ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` 168to :ref:`log a warning <asyncio-logger>` to detect it. 212 loop = asyncio.get_event_loop() 213 asyncio.ensure_future(bug()) 214 loop.run_forever() 229 230:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 231traceback where the task was created. Output in debug mode:: 370 371:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 372traceback where the task was created. Example of log in debug mode::test_asyncio.py git://github.com/zeromq/pyzmq.git | Python | 498 lines
16import zmq.asyncio as zaio 17from zmq.auth.asyncio import AsyncioAuthenticator 18from zmq.tests import BaseZMQTestCase 38 loop = asyncio.new_event_loop() 39 coro = asyncio.wait_for(never_ending_task(socket), timeout=1) 40 try: 53 def setUp(self): 54 self.loop = asyncio.new_event_loop() 55 asyncio.set_event_loop(self.loop) 191 f = b.recv_json() 192 recvd = await asyncio.wait_for(f, timeout=5) 193 assert recvd == obj 407 asyncio.set_event_loop(loop) 408 loop.run_until_complete(asyncio.wait_for(test(), timeout=10)) 409 loop.close()__init__.py https://bitbucket.org/echarles5wits/kioskcommutility.git | Python | 104 lines
1import asyncio 2import sys 13 Useful in cases when you want to apply timeout logic around block 14 of code or in cases when asyncio.wait_for is not suitable. For example: 15 21 timeout - value in seconds or None to disable timeout logic 22 loop - asyncio compatible event loop 23 """ 26 if loop is None: 27 loop = asyncio.get_event_loop() 28 self._loop = loop 39 40 @asyncio.coroutine 41 def __aenter__(self): 60 # Support Tornado 5- without timeout 61 # Details: https://github.com/python/asyncio/issues/392 62 if self._timeout is None:demo_face.py https://bitbucket.org/lilyzhang622/cozmo-demos.git | Python | 106 lines
1#!/usr/bin/env python3 2''' 9import time 10import asyncio 11 46 robot.move_lift(-3) 47 robot.set_head_angle(cozmo.robot.MAX_HEAD_ANGLE).wait_for_completed() 48 69 face = None 70 face = robot.world.wait_for_observed_face(timeout=30) 71 if face in faces: 71 if face in faces: 72 robot.say_text("Hello again!").wait_for_completed() 73 turn_action = robot.turn_towards_face(face) 75 faces.append(face) 76 robot.say_text("Hello New Person!").wait_for_completed() 77 except asyncio.TimeoutError:server_base.py https://bitbucket.org/arfonzo/electrumx4egc.git | Python | 128 lines
7 8import asyncio 9import os 22 23 - set PYTHON_MIN_VERSION and SUPPRESS_MESSAGES as appropriate 24 - implement the start_servers() coroutine, called from the run() method. 33 34 PYTHON_MIN_VERSION = (3, 6) 35 43 # Sanity checks 44 if sys.version_info < self.PYTHON_MIN_VERSION: 45 mvs = '.'.join(str(part) for part in self.PYTHON_MIN_VERSION) 45 mvs = '.'.join(str(part) for part in self.PYTHON_MIN_VERSION) 46 raise RuntimeError('Python version >= {} is required'.format(mvs)) 47DESCRIPTION.rst https://bitbucket.org/echarles5wits/kioskcommutility.git | ReStructuredText | 134 lines
7.. image:: https://img.shields.io/pypi/v/async-timeout.svg 8 :target: https://pypi.python.org/pypi/async-timeout 9.. image:: https://badges.gitter.im/Join%20Chat.svg 12 13asyncio-compatible timeout context manager. 14 20The context manager is useful in cases when you want to apply timeout 21logic around block of code or in cases when ``asyncio.wait_for()`` is 22not suitable. Also it's much faster than ``asyncio.wait_for()`` 332. Otherwise ``inner()`` is cancelled internally by sending 34 ``asyncio.CancelledError`` into but ``asyncio.TimeoutError`` is 35 raised outside of context manager scope. 59 60The library is Python 3 only! 61image.py https://bitbucket.org/btirelan86/chibibot.git | Python | 168 lines
4import functools 5import asyncio 6 7try: 8 from imgurpython import ImgurClient 9except: 43 try: 44 results = await asyncio.wait_for(task, timeout=10) 45 except asyncio.TimeoutError: 63 try: 64 results = await asyncio.wait_for(task, timeout=10) 65 except asyncio.TimeoutError: 103 try: 104 items = await asyncio.wait_for(task, timeout=10) 105 except asyncio.TimeoutError:p2p_invalid_messages.py git://github.com/bitcoin/bitcoin.git | Python | 241 lines
1#!/usr/bin/env python3 2# Copyright (c) 2015-2020 The Bitcoin Core developers 5"""Test node responses to invalid network messages.""" 6import asyncio 7import struct 94 # Under macOS this test is skipped due to an unexpected error code 95 # returned from the closing socket which python/asyncio does not 96 # yet know how to handle. 104 node.p2p.send_message(msg_over_size) 105 node.p2p.wait_for_disconnect(timeout=4) 106 108 conn = node.add_p2p_connection(P2PDataStore()) 109 conn.wait_for_verack() 110 else: 141 142 node.p2p.wait_for_disconnect(timeout=10) 143 node.disconnect_p2ps()roster_browser.py https://github.com/louiz/SleekXMPP.git | Python | 142 lines
1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 17from slixmpp.exceptions import IqError, IqTimeout 18from slixmpp.xmlstream.asyncio import asyncio 19 35 self.add_event_handler("session_start", self.start) 36 self.add_event_handler("changed_status", self.wait_for_presences) 37 38 self.received = set() 39 self.presences_received = asyncio.Event() 40 40 41 @asyncio.coroutine 42 def start(self, event): 54 """ 55 future = asyncio.Future() 56 def callback(result):SenderChannel.py https://bitbucket.org/selfStabilizingAtomicStorage/datx05-code.git | Python | 156 lines
1#!/bin/python3.6 2# -*- coding: utf-8 -*- 26 27import asyncio 28import struct 52 53 self.loop = asyncio.get_event_loop() 54 self.udp = True 68 if self.udp: 69 res, addr = await asyncio.wait_for(self.udp_sock.recvfrom(self.chunks_size), self.udp_timeout) 70 else: 94 token = struct.pack("ii17s", self.ch_type, counter, self.uid) 95 await asyncio.sleep(2) 96 await self.udp_sock.sendto(token, self.addr) 138 while True: 139 res_part = await asyncio.wait_for(self.loop.sock_recv(self.tc_sock, self.chunks_size), self.tcp_timeout) 140 if not res_part:_dask.py https://github.com/joblib/joblib.git | Python | 366 lines
33 try: 34 # asyncio.TimeoutError, Python3-only error thrown by recent versions of 35 # distributed 56 Furthermore using a dict with id(array) as key is not safe because the 57 Python is likely to reuse id of recently collected arrays. 58 """ 146 def __init__(self, scheduler_host=None, scatter=None, 147 client=None, loop=None, wait_for_workers_timeout=10, 148 **submit_kwargs): 186 self.data_futures = {} 187 self.wait_for_workers_timeout = wait_for_workers_timeout 188 self.submit_kwargs = submit_kwargs 208 callback(result) 209 await asyncio.sleep(0.01) 210__init__.py https://github.com/rapid7/metasploit-framework.git | Python | 101 lines
4 5import asyncio 6 14 Useful in cases when you want to apply timeout logic around block 15 of code or in cases when asyncio.wait_for is not suitable. For example: 16 22 timeout - value in seconds or None to disable timeout logic 23 loop - asyncio compatible event loop 24 """ 27 if loop is None: 28 loop = asyncio.get_event_loop() 29 self._loop = loop 61 # Support Tornado 5- without timeout 62 # Details: https://github.com/python/asyncio/issues/392 63 if self._timeout is None:functions.py https://bitbucket.org/alexanderpaul/marinas-utility-music.git | Python | 222 lines
2import sys 3import asyncio 4# my modules 18 await Bot.logout() 19 # reruns the python script 20 python = sys.executable 20 python = sys.executable 21 os.execl(python, python, 'main.py') 22 else: 106 print('Invalid number caught!') 107 asyncio.run_coroutine_threadsafe(Message.channel.send('Number {} is not in search results.'.format(number)), Bot.loop) 108 return False 110 print('Value Error Exception!') 111 asyncio.run_coroutine_threadsafe(Message.channel.send('Invalid input. Make sure to enter a number.'), Bot.loop) 112 return Falsedownload_avatars.py https://github.com/louiz/SleekXMPP.git | Python | 165 lines
1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 17from slixmpp.exceptions import XMPPError 18from slixmpp import asyncio 19 36 self.add_event_handler("session_start", self.start) 37 self.add_event_handler("changed_status", self.wait_for_presences) 38 42 self.received = set() 43 self.presences_received = asyncio.Event() 44 self.roster_received = asyncio.Event() 49 50 @asyncio.coroutine 51 def start(self, event): 72 73 @asyncio.coroutine 74 def on_vcard_avatar(self, pres):ipc.py https://bitbucket.org/hackersgame/lavinder-prototype.git | Python | 221 lines
23 use marshal to serialize data - this means that both client and server must 24 run the same Python version, and that clients must be trusted (as 25 un-marshalling untrusted data can result in arbitrary code execution). 33 34from six.moves import asyncio 35 64 65class _ClientProtocol(asyncio.Protocol, _IPC): 66 """IPC Client Protocol 82 self.recv = b'' 83 self.reply = asyncio.Future() 84 129 try: 130 self.loop.run_until_complete(asyncio.wait_for(client_proto.reply, timeout=10)) 131 except asyncio.TimeoutError:__init__.py https://bitbucket.org/inbar_donag_/advisor-pro-server-test.git | Python | 97 lines
1import asyncio 2 10 Useful in cases when you want to apply timeout logic around block 11 of code or in cases when asyncio.wait_for is not suitable. For example: 12 18 timeout - value in seconds or None to disable timeout logic 19 loop - asyncio compatible event loop 20 """ 23 if loop is None: 24 loop = asyncio.get_event_loop() 25 self._loop = loop 36 37 @asyncio.coroutine 38 def __aenter__(self): 57 # Support Tornado 5- without timeout 58 # Details: https://github.com/python/asyncio/issues/392 59 if self._timeout is None:python-asyncio-note-control-Coroutines.rst https://gitlab.com/mozillazg/blog | ReStructuredText | 380 lines
3 4:slug: python-asyncio-note-control-Coroutines 5:date: 2017-08-25 61 62 $ python3.6 asyncio_wait.py 63 starting main 302 303 $ python3.6 asyncio_gather.py 304 starting main 359 360 $ python3.6 asyncio_as_completed.py 361 starting main 379- `18.5.3. Tasks and coroutines — Python 3.6.2 380 documentation <https://docs.python.org/3.6/library/asyncio-task.html>`__ 381test_asyncio.py https://github.com/zeromq/pyzmq.git | Python | 499 lines
17import zmq.asyncio as zaio 18from zmq.auth.asyncio import AsyncioAuthenticator 19 41 loop = asyncio.get_event_loop() 42 coro = asyncio.wait_for(never_ending_task(socket), timeout=1) 43 try: 175 # cycle eventloop to allow cancel events to fire 176 await asyncio.sleep(0) 177 obj = dict(a=5) 192 f = b.recv_json() 193 recvd = await asyncio.wait_for(f, timeout=5) 194 assert recvd == obj 408 asyncio.set_event_loop(loop) 409 loop.run_until_complete(asyncio.wait_for(test(), timeout=10)) 410 loop.close()asyncio_socket.py https://bitbucket.org/codengine/auction.git | Python | 213 lines
18 try: 19 packets = [await asyncio.wait_for(self.queue.get(), 20 self.server.ping_timeout)] 21 self.queue.task_done() 22 except (asyncio.TimeoutError, asyncio.CancelledError): 23 raise exceptions.QueueEmpty() 174 p = None 175 wait_task = asyncio.ensure_future(ws.wait()) 176 try: 176 try: 177 p = await asyncio.wait_for(wait_task, self.server.ping_timeout) 178 except asyncio.CancelledError: # pragma: no cover 211 await self.queue.put(None) # unlock the writer task so it can exit 212 await asyncio.wait_for(writer_task, timeout=None) 213 await self.close(wait=True, abort=True)async_engine.py https://github.com/funtoo/funtoo-overlay.git | Python | 55 lines
1#!/usr/bin/python3 2 2 3import asyncio 4from concurrent.futures import ThreadPoolExecutor 16 self.workers = [] 17 self.loop = asyncio.get_event_loop() 18 self.keep_running = True 39 40 async def wait_for_workers_to_finish(self): 41 self.keep_running = False 41 self.keep_running = False 42 await asyncio.gather(*self.workers) 43 46 self.loop.run_until_complete(asyncio.gather( 47 asyncio.ensure_future(self.wait_for_workers_to_finish()) 48 ))ipc.py https://github.com/dequis/qtile.git | Python | 249 lines
23 use marshal to serialize data - this means that both client and server must 24 run the same Python version, and that clients must be trusted (as 25 un-marshalling untrusted data can result in arbitrary code execution). 33 34from . import asyncio 35 81 82class _ClientProtocol(asyncio.Protocol, _IPC): 83 """IPC Client Protocol 99 self.recv = b'' 100 self.reply = asyncio.Future() 101 151 try: 152 self.loop.run_until_complete(asyncio.wait_for(client_proto.reply, timeout=10)) 153 except asyncio.TimeoutError:test_noncoap_client.py https://gitlab.com/aiocoap/aiocoap | Python | 174 lines
14import asyncio 15from asyncio import wait_for, TimeoutError 16import signal 87 self.mocksock.send(b'\x40') 88 await asyncio.sleep(0.1) 89 107 self.mocksock.send(b'\x40\x01\x99\x99') # that's a GET / 108 await asyncio.sleep(0.1) 109 r1 = r2 = None 110 try: 111 r1 = await wait_for(self.mocksock.recv(), timeout=1) 112 r2 = await wait_for(self.mocksock.recv(), timeout=1) 121 self.mocksock.send(b'\x40\x00\x99\x9a') # CoAP ping -- should this test be doable in aiocoap? 122 response = await asyncio.wait_for(self.mocksock.recv(), timeout=1) 123 assert response == b'\x70\x00\x99\x9a'client.py https://bitbucket.org/uva-sne/vnet-ui-cli.git | Python | 426 lines
3import json 4import asyncio 5 20 self.identifier = {'version': 'sc17-0.1', 21 'agent': 'python3/websockets', 22 'screen': '0x0@1', 35 try: 36 msg = await asyncio.wait_for(self.ws.recv(), timeout=20) 37 except asyncio.TimeoutError: 40 pong_waiter = await self.ws.ping() 41 await asyncio.wait_for(pong_waiter, timeout=10) 42 except asyncio.TimeoutError: 43 # No response to ping in 10 seconds, disconnect. 44 raise asyncio.TimeoutError 45 else:test_tasks.py https://bitbucket.org/jaraco/cpython-issue13540 | Python | 1963 lines
13from asyncio import coroutines 14from asyncio import test_utils 15 20 21@asyncio.coroutine 22def coroutine_function(): 53 def test_task_class(self): 54 @asyncio.coroutine 55 def notmuch(): 265 fut = asyncio.Future(loop=self.loop) 266 task = asyncio.Task(wait_for(fut), loop=self.loop) 267 test_utils.run_briefly(self.loop) 400 yield from fut2 401 except asyncio.CancelledError: 402 passhttpclients.py https://github.com/vincentbernat/network-lab.git | Python | 101 lines
1#!/usr/bin/env python3 2 17import aiohttp 18import asyncio 19import json 34 await asyncio.sleep(random.random()*5) 35 got = await asyncio.wait_for(resp.content.readany(), timeout=2) 36 if not got or random.random() > 0.95: 54 if len(pending) >= parallel: 55 done, pending = await asyncio.wait( 56 pending, 56 pending, 57 return_when=asyncio.FIRST_COMPLETED) 58 for d in done: 96sources = get_sources() 97loop = asyncio.get_event_loop() 98try:test_tasks.py https://bitbucket.org/yomgui/cpython | Python | 1985 lines
14from asyncio import coroutines 15from asyncio import test_utils 16 21 22@asyncio.coroutine 23def coroutine_function(): 54 def test_task_class(self): 55 @asyncio.coroutine 56 def notmuch(): 266 fut = asyncio.Future(loop=self.loop) 267 task = asyncio.Task(wait_for(fut), loop=self.loop) 268 test_utils.run_briefly(self.loop) 396 397 @asyncio.coroutine 398 def task():asyncio-dev.rst https://bitbucket.org/TJG/cpython | ReStructuredText | 397 lines
23* Enable the asyncio debug mode globally by setting the environment variable 24 :envvar:`PYTHONASYNCIODEBUG` to ``1`` 25* Set the log level of the :ref:`asyncio logger <asyncio-logger>` to 166of the coroutine object will never be scheduled which is probably a bug. 167:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to :ref:`log a 168warning <asyncio-logger>` to detect it. 212 loop = asyncio.get_event_loop() 213 asyncio.async(bug()) 214 loop.run_forever() 229 230:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 231traceback where the task was created. Output in debug mode:: 370 371:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 372traceback where the task was created. Example of log in debug mode::component.py https://github.com/tavendo/AutobahnPython.git | Python | 420 lines
161 ) 162 time_f = asyncio.ensure_future(asyncio.wait_for(f, timeout=timeout)) 163 return self._wrap_connection_future(transport, done, time_f) 222 ) 223 time_f = asyncio.ensure_future(asyncio.wait_for(f, timeout=timeout)) 224 return self._wrap_connection_future(transport, done, time_f) 233 ) 234 time_f = asyncio.ensure_future(asyncio.wait_for(f, timeout=timeout)) 235 return self._wrap_connection_future(transport, done, time_f) 346 if loop.is_closed(): 347 asyncio.set_event_loop(asyncio.new_event_loop()) 348 loop = asyncio.get_event_loop() 351 352 # see https://github.com/python/asyncio/issues/341 asyncio has 353 # "odd" handling of KeyboardInterrupt when using Tasks (asfunction_key_tabs.rst https://github.com/gnachman/iTerm2.git | ReStructuredText | 66 lines
9 10.. code-block:: python 11 11 12 #!/usr/bin/env python3 13 13 14 import asyncio 15 import iterm2 55 # Run the monitor in the background 56 asyncio.create_task(monitor()) 57 60 async with filter as mon: 61 await iterm2.async_wait_forever() 62test_tasks.py https://bitbucket.org/TJG/cpython | Python | 2020 lines
10 11import asyncio 12from asyncio import coroutines 12from asyncio import coroutines 13from asyncio import test_utils 14try: 15 from test import support 16 from test.script_helper import assert_python_ok 17except ImportError: 18 from asyncio import test_support as support 19 from asyncio.test_support import assert_python_ok 20 273 fut = asyncio.Future(loop=self.loop) 274 task = asyncio.Task(wait_for(fut), loop=self.loop) 275 test_utils.run_briefly(self.loop)tasks.py https://bitbucket.org/ctheune/cpython | Python | 707 lines
5 'FIRST_COMPLETED', 'FIRST_EXCEPTION', 'ALL_COMPLETED', 6 'wait', 'wait_for', 'as_completed', 'sleep', 'async', 7 'gather', 'shield', 32_DEBUG = (not sys.flags.ignore_environment 33 and bool(os.environ.get('PYTHONASYNCIODEBUG'))) 34 52 def send(self, *value): 53 # We use `*value` because of a bug in CPythons prior 54 # to 3.4.1. See issue #21209 and test_yield_from_corowrapper 381 382 done, pending = yield from asyncio.wait(fs) 383 418 419 result = yield from asyncio.wait_for(fut, 10.0) 420test_tasks.py https://bitbucket.org/ctheune/cpython | Python | 1721 lines
379 with self.assertRaises(asyncio.TimeoutError): 380 loop.run_until_complete(asyncio.wait_for(fut, 0.1, loop=loop)) 381 self.assertTrue(fut.done()) 394 395 res = loop.run_until_complete(asyncio.wait_for(coro(), 396 timeout=None, 420 with self.assertRaises(asyncio.TimeoutError): 421 loop.run_until_complete(asyncio.wait_for(fut, 0.01)) 422 finally: 440 441 a = asyncio.Task(asyncio.sleep(0.1, loop=loop), loop=loop) 442 b = asyncio.Task(asyncio.sleep(0.15, loop=loop), loop=loop) 512 ValueError, self.loop.run_until_complete, 513 asyncio.wait([asyncio.sleep(10.0, loop=self.loop)], 514 return_when=-1, loop=self.loop))asyncio-dev.rst https://bitbucket.org/ncoghlan/cpython_sandbox | ReStructuredText | 403 lines
23* Enable the asyncio debug mode globally by setting the environment variable 24 :envvar:`PYTHONASYNCIODEBUG` to ``1``, or by calling :meth:`BaseEventLoop.set_debug`. 25* Set the log level of the :ref:`asyncio logger <asyncio-logger>` to 172the execution of the coroutine object will never be scheduled which is 173probably a bug. :ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` 174to :ref:`log a warning <asyncio-logger>` to detect it. 227 Traceback (most recent call last): 228 File "asyncio/tasks.py", line 237, in _step 229 result = next(coro) 235 236:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 237traceback where the task was created. Output in debug mode:: 376 377:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the 378traceback where the task was created. Example of log in debug mode::mllp.rst https://github.com/johnpaulett/python-hl7.git | ReStructuredText | 121 lines
1MLLP using asyncio 2================== 16the `asyncio.streams` package. `Examples in that documentation 17<https://docs.python.org/3/library/asyncio-stream.html>`_ 18may be of assistance in writing production senders and 23 24.. code:: python 25 25 26 # Using the third party `aiorun` instead of the `asyncio.run()` to avoid 27 # boilerplate. 42 # a dead receiver won't block you for long 43 hl7_reader, hl7_writer = await asyncio.wait_for( 44 open_hl7_connection("127.0.0.1", 2575), 56 # Now wait for the ACK message from the receiever 57 hl7_ack = await asyncio.wait_for( 58 hl7_reader.readmessage(),