Skip to content

Commit bc4c4eb

Browse files
committed
Support unpublished event loop's current_task api
1 parent 67fab6c commit bc4c4eb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGES
22
=======
33

4+
1.2.1 (2017-05-02)
5+
------------------
6+
7+
* Support unpublished event loop's "current_task" api.
8+
9+
410
1.2.0 (2017-03-11)
511
------------------
612

async_timeout/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22

33

4-
__version__ = '1.2.0'
4+
__version__ = '1.2.1'
55

66

77
class timeout:
@@ -31,7 +31,7 @@ def __init__(self, timeout, *, loop=None):
3131

3232
def __enter__(self):
3333
if self._timeout is not None:
34-
self._task = asyncio.Task.current_task(loop=self._loop)
34+
self._task = current_task(self._loop)
3535
if self._task is None:
3636
raise RuntimeError('Timeout context manager should be used '
3737
'inside a task')
@@ -51,3 +51,12 @@ def __exit__(self, exc_type, exc_val, exc_tb):
5151

5252
def _cancel_task(self):
5353
self._cancelled = self._task.cancel()
54+
55+
56+
def current_task(loop):
57+
task = asyncio.Task.current_task(loop=loop)
58+
if task is None:
59+
if hasattr(loop, 'current_task'):
60+
task = loop.current_task()
61+
62+
return task

0 commit comments

Comments
 (0)