Skip to content

Commit d260c31

Browse files
committed
Make Future/Task compatible with asyncio in Python 3.6
1 parent db70c2b commit d260c31

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

uvloop/future.pyx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ DEF _FUT_CANCELLED = 2
55
DEF _FUT_FINISHED = 3
66

77

8+
cdef inline _future_get_blocking(fut):
9+
try:
10+
return fut._asyncio_future_blocking
11+
except AttributeError:
12+
return fut._blocking
13+
14+
15+
cdef inline _future_set_blocking(fut, val):
16+
try:
17+
fut._asyncio_future_blocking
18+
except AttributeError:
19+
fut._blocking = val
20+
else:
21+
fut._asyncio_future_blocking = val
22+
23+
824
cdef class BaseFuture:
925
cdef:
1026
int _state
@@ -36,6 +52,13 @@ cdef class BaseFuture:
3652
else:
3753
self._source_traceback = None
3854

55+
property _asyncio_future_blocking:
56+
def __get__(self):
57+
return self._blocking
58+
59+
def __set__(self, value):
60+
self._blocking = value
61+
3962
cdef _schedule_callbacks(self):
4063
cdef:
4164
list callbacks

uvloop/task.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ cdef class BaseTask(BaseFuture):
156156
# Yielded Future must come from Future.__iter__().
157157
if result._loop is not self._loop:
158158
self._raise_wrong_loop(result)
159-
elif result._blocking:
160-
result._blocking = False
159+
elif _future_get_blocking(result):
160+
_future_set_blocking(result, False)
161161
result.add_done_callback(self._wakeup)
162162
self._fut_waiter = result
163163
if self._must_cancel:

0 commit comments

Comments
 (0)