twisteroidambassador / async_stagger Goto Github PK
View Code? Open in Web Editor NEWHappy Eyeballs connection algorithm and underlying scheduling logic in asyncio
License: MIT License
Happy Eyeballs connection algorithm and underlying scheduling logic in asyncio
License: MIT License
Hello,
I see in the docs: "async_stagger requires Python 3.6 or later. ... It does not have any external dependencies."
But on Python 3.7.3 I get an error:
Traceback (most recent call last):
File "prettysocks.py", line 34, in <module>
from typing import Callable, Awaitable, Tuple, Union
File "/tmp/prettysocks/typing.py", line 3, in <module>
from typing import Tuple, Union
ImportError: cannot import name 'Tuple' from 'typing' (/tmp/prettysocks/typing.py)
What am I missing?
Note that I did not "pip install" the package, instead I copied all the async_stagger files directly into the same folder as prettysocks, and launch the latter.
============================= test session starts ==============================
platform linux -- Python 3.9.0rc2, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /build/async_stagger-0.3.0
plugins: asyncio-0.14.0, mock-3.2.0
collected 40 items
async_stagger/test_aitertools.py ....... [ 17%]
async_stagger/test_happy_eyeballs.py ........... [ 45%]
async_stagger/test_resolver.py .................. [ 90%]
async_stagger/test_stagger.py F.F. [100%]
=================================== FAILURES ===================================
__________________________ test_stagger_random_tasks ___________________________
@pytest.mark.asyncio
async def test_stagger_random_tasks():
for _ in range(10):
> await random_tasks()
async_stagger/test_stagger.py:20:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
async def random_tasks():
async def one_coro(index, sleep_for, succeed):
print('Coroutine %d starting, will sleep for %f' % (index, sleep_for))
await asyncio.sleep(sleep_for)
if succeed:
print('Coroutine %d finishing' % index)
return index
else:
print('Coroutine %d raising RuntimeError' % index)
raise RuntimeError
coro_fns = aiter_from_iter(
partial(one_coro, i, random.random() * 2, random.random() < 0.8)
for i in range(10))
delay = 0.3
winner_result, winner_idx, exc, aiter_exc = \
await staggered_race(coro_fns, delay)
if winner_idx is not None:
assert winner_result == winner_idx
for i, e in enumerate(exc):
if i == winner_idx:
assert e is None
else:
> assert isinstance(e, (RuntimeError, asyncio.CancelledError))
E AssertionError: assert False
E + where False = isinstance(None, (<class 'RuntimeError'>, <class 'asyncio.exceptions.CancelledError'>))
async_stagger/test_stagger.py:46: AssertionError
----------------------------- Captured stdout call -----------------------------
Coroutine 0 starting, will sleep for 0.506632
Coroutine 1 starting, will sleep for 1.748210
Coroutine 0 finishing
________________________ test_stagger_simultaneous_done ________________________
@pytest.mark.asyncio
async def test_stagger_simultaneous_done():
for _ in range(5):
> await simultaneous_done()
async_stagger/test_stagger.py:78:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
async def simultaneous_done():
coro_fns = aiter_from_iter(
partial(asyncio.sleep, i*0.2) for i in range(5, 0, -1))
winner_result, winner_idx, exceptions, aiter_exc = \
await staggered_race(coro_fns, 0.2)
assert winner_idx is not None
> assert all(isinstance(e, asyncio.CancelledError)
for i, e in enumerate(exceptions)
if i != winner_idx)
E assert False
E + where False = all(<generator object simultaneous_done.<locals>.<genexpr> at 0x7ffff61e5190>)
async_stagger/test_stagger.py:87: AssertionError
=========================== short test summary info ============================
FAILED async_stagger/test_stagger.py::test_stagger_random_tasks - AssertionEr...
FAILED async_stagger/test_stagger.py::test_stagger_simultaneous_done - assert...
======================== 2 failed, 38 passed in 27.47s =========================
In _connect_sock
, when:
local_addr_infos
contains several addresses,loop.sock_connect
raises an exception,then the exceptions saved in bind_exceptions
are lost. The user has no opportunity to see the exceptions. In asyncio
, all exceptions including those raised during bind and connect are collected, and potentially combined into a single exception, where the user can at least see the str
of all individual exceptions.
happy_eyeballs.py
makes provisions for UDP.
What's the rationale?
Is connect()
of UDP socket expected to take unpredictable amount of time?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.