Skip to content
Snippets Groups Projects
Commit a5f2970d authored by Piotr Ożarowski's avatar Piotr Ożarowski
Browse files

Import python-async-timeout_2.0.0.orig.tar.gz

parent 5c96aee6
No related branches found
No related tags found
No related merge requests found
CHANGES
=======
2.0.0 (2017-10-09)
------------------
* Changed `timeout <= 0` behaviour
* Backward incompatibility change, prior this version `0` was
shortcut for `None`
* when timeout <= 0 `TimeoutError` raised faster
1.4.0 (2017-09-09)
------------------
......
Metadata-Version: 1.1
Name: async-timeout
Version: 1.4.0
Version: 2.0.0
Summary: Timeout context manager for asyncio programs
Home-page: https://github.com/aio-libs/async_timeout/
Author: Andrew Svetlov
......@@ -80,6 +80,15 @@ Description: async-timeout
CHANGES
=======
2.0.0 (2017-10-09)
------------------
* Changed `timeout <= 0` behaviour
* Backward incompatibility change, prior this version `0` was
shortcut for `None`
* when timeout <= 0 `TimeoutError` raised faster
1.4.0 (2017-09-09)
------------------
......
Metadata-Version: 1.1
Name: async-timeout
Version: 1.4.0
Version: 2.0.0
Summary: Timeout context manager for asyncio programs
Home-page: https://github.com/aio-libs/async_timeout/
Author: Andrew Svetlov
......@@ -80,6 +80,15 @@ Description: async-timeout
CHANGES
=======
2.0.0 (2017-10-09)
------------------
* Changed `timeout <= 0` behaviour
* Backward incompatibility change, prior this version `0` was
shortcut for `None`
* when timeout <= 0 `TimeoutError` raised faster
1.4.0 (2017-09-09)
------------------
......
import asyncio
__version__ = '1.4.0'
__version__ = '2.0.0'
class timeout:
......@@ -19,8 +19,6 @@ class timeout:
loop - asyncio compatible event loop
"""
def __init__(self, timeout, *, loop=None):
if timeout is not None and timeout == 0:
timeout = None
self._timeout = timeout
if loop is None:
loop = asyncio.get_event_loop()
......@@ -56,13 +54,23 @@ class timeout:
return None
def _do_enter(self):
if self._timeout is not None:
self._task = current_task(self._loop)
if self._task is None:
raise RuntimeError('Timeout context manager should be used '
'inside a task')
self._cancel_at = self._loop.time() + self._timeout
self._cancel_handler = self._loop.call_at(self._cancel_at, self._cancel_task)
# Support Tornado 5- without timeout
# Details: https://github.com/python/asyncio/issues/392
if self._timeout is None:
return self
self._task = current_task(self._loop)
if self._task is None:
raise RuntimeError('Timeout context manager should be used '
'inside a task')
if self._timeout <= 0:
self._loop.call_soon(self._cancel_task)
return self
self._cancel_at = self._loop.time() + self._timeout
self._cancel_handler = self._loop.call_at(
self._cancel_at, self._cancel_task)
return self
def _do_exit(self, exc_type):
......
......@@ -16,3 +16,26 @@ async def test_async_no_timeout(loop):
async with timeout(1, loop=loop) as cm:
await asyncio.sleep(0, loop=loop)
assert not cm.expired
async def test_async_zero(loop):
with pytest.raises(asyncio.TimeoutError):
async with timeout(0, loop=loop) as cm:
await asyncio.sleep(10, loop=loop)
assert cm.expired
async def test_async_zero_coro_not_started(loop):
coro_started = False
async def coro():
nonlocal coro_started
coro_started = True
with pytest.raises(asyncio.TimeoutError):
async with timeout(0, loop=loop) as cm:
await asyncio.sleep(0, loop=loop)
await coro()
assert cm.expired
assert coro_started is False
......@@ -80,19 +80,36 @@ def test_timeout_disable(loop):
assert 0.09 < dt < 0.13, dt
def test_timeout_is_none_no_task(loop):
with timeout(None, loop=loop) as cm:
assert cm._task is None
@asyncio.coroutine
def test_timeout_enable_zero(loop):
with pytest.raises(asyncio.TimeoutError):
with timeout(0, loop=loop) as cm:
yield from asyncio.sleep(0.1, loop=loop)
assert cm.expired
@asyncio.coroutine
def test_timeout_disable_zero(loop):
def test_timeout_enable_zero_coro_not_started(loop):
coro_started = False
@asyncio.coroutine
def long_running_task():
yield from asyncio.sleep(0.1, loop=loop)
return 'done'
def coro():
nonlocal coro_started
coro_started = True
t0 = loop.time()
with timeout(0, loop=loop):
resp = yield from long_running_task()
assert resp == 'done'
dt = loop.time() - t0
assert 0.09 < dt < 0.13, dt
with pytest.raises(asyncio.TimeoutError):
with timeout(0, loop=loop) as cm:
yield from asyncio.sleep(0, loop=loop)
yield from coro()
assert cm.expired
assert coro_started is False
@asyncio.coroutine
......@@ -104,7 +121,7 @@ def test_timeout_not_relevant_exception(loop):
@asyncio.coroutine
def test_timeout_canceled_error_is_converted_to_timeout(loop):
def test_timeout_canceled_error_is_not_converted_to_timeout(loop):
yield from asyncio.sleep(0, loop=loop)
with pytest.raises(asyncio.CancelledError):
with timeout(0.001, loop=loop):
......@@ -228,6 +245,7 @@ def test_timeout_inner_other_error(loop):
raise RuntimeError
assert not cm.expired
@asyncio.coroutine
def test_timeout_remaining(loop):
with timeout(None, loop=loop) as cm:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment