This repository was archived by the owner on Nov 23, 2017. It is now read-only.
File tree 2 files changed +25
-7
lines changed
2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -241,7 +241,7 @@ def _step(self, exc=None):
241
241
result = coro .throw (exc )
242
242
except StopIteration as exc :
243
243
self .set_result (exc .value )
244
- except futures .CancelledError as exc :
244
+ except futures .CancelledError :
245
245
super ().cancel () # I.e., Future.cancel(self).
246
246
except Exception as exc :
247
247
self .set_exception (exc )
@@ -259,12 +259,19 @@ def _step(self, exc=None):
259
259
'Task {!r} got Future {!r} attached to a '
260
260
'different loop' .format (self , result )))
261
261
elif blocking :
262
- result ._asyncio_future_blocking = False
263
- result .add_done_callback (self ._wakeup )
264
- self ._fut_waiter = result
265
- if self ._must_cancel :
266
- if self ._fut_waiter .cancel ():
267
- self ._must_cancel = False
262
+ if result is self :
263
+ self ._loop .call_soon (
264
+ self ._step ,
265
+ RuntimeError (
266
+ 'Task cannot await on itself: {!r}' .format (
267
+ self )))
268
+ else :
269
+ result ._asyncio_future_blocking = False
270
+ result .add_done_callback (self ._wakeup )
271
+ self ._fut_waiter = result
272
+ if self ._must_cancel :
273
+ if self ._fut_waiter .cancel ():
274
+ self ._must_cancel = False
268
275
else :
269
276
self ._loop .call_soon (
270
277
self ._step ,
Original file line number Diff line number Diff line change @@ -92,6 +92,17 @@ def run(fut):
92
92
finally :
93
93
other_loop .close ()
94
94
95
+ def test_task_awaits_on_itself (self ):
96
+ @asyncio .coroutine
97
+ def test ():
98
+ yield from task
99
+
100
+ task = asyncio .ensure_future (test (), loop = self .loop )
101
+
102
+ with self .assertRaisesRegex (RuntimeError ,
103
+ 'Task cannot await on itself' ):
104
+ self .loop .run_until_complete (task )
105
+
95
106
def test_task_class (self ):
96
107
@asyncio .coroutine
97
108
def notmuch ():
You can’t perform that action at this time.
0 commit comments