mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #27972: Prohibit Tasks to await on themselves.
This commit is contained in:
parent
908d55dd7e
commit
4145c83806
3 changed files with 27 additions and 7 deletions
|
@ -241,7 +241,7 @@ class Task(futures.Future):
|
||||||
result = coro.throw(exc)
|
result = coro.throw(exc)
|
||||||
except StopIteration as exc:
|
except StopIteration as exc:
|
||||||
self.set_result(exc.value)
|
self.set_result(exc.value)
|
||||||
except futures.CancelledError as exc:
|
except futures.CancelledError:
|
||||||
super().cancel() # I.e., Future.cancel(self).
|
super().cancel() # I.e., Future.cancel(self).
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.set_exception(exc)
|
self.set_exception(exc)
|
||||||
|
@ -259,12 +259,19 @@ class Task(futures.Future):
|
||||||
'Task {!r} got Future {!r} attached to a '
|
'Task {!r} got Future {!r} attached to a '
|
||||||
'different loop'.format(self, result)))
|
'different loop'.format(self, result)))
|
||||||
elif blocking:
|
elif blocking:
|
||||||
result._asyncio_future_blocking = False
|
if result is self:
|
||||||
result.add_done_callback(self._wakeup)
|
self._loop.call_soon(
|
||||||
self._fut_waiter = result
|
self._step,
|
||||||
if self._must_cancel:
|
RuntimeError(
|
||||||
if self._fut_waiter.cancel():
|
'Task cannot await on itself: {!r}'.format(
|
||||||
self._must_cancel = False
|
self)))
|
||||||
|
else:
|
||||||
|
result._asyncio_future_blocking = False
|
||||||
|
result.add_done_callback(self._wakeup)
|
||||||
|
self._fut_waiter = result
|
||||||
|
if self._must_cancel:
|
||||||
|
if self._fut_waiter.cancel():
|
||||||
|
self._must_cancel = False
|
||||||
else:
|
else:
|
||||||
self._loop.call_soon(
|
self._loop.call_soon(
|
||||||
self._step,
|
self._step,
|
||||||
|
|
|
@ -92,6 +92,17 @@ class TaskTests(test_utils.TestCase):
|
||||||
finally:
|
finally:
|
||||||
other_loop.close()
|
other_loop.close()
|
||||||
|
|
||||||
|
def test_task_awaits_on_itself(self):
|
||||||
|
@asyncio.coroutine
|
||||||
|
def test():
|
||||||
|
yield from task
|
||||||
|
|
||||||
|
task = asyncio.ensure_future(test(), loop=self.loop)
|
||||||
|
|
||||||
|
with self.assertRaisesRegex(RuntimeError,
|
||||||
|
'Task cannot await on itself'):
|
||||||
|
self.loop.run_until_complete(task)
|
||||||
|
|
||||||
def test_task_class(self):
|
def test_task_class(self):
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def notmuch():
|
def notmuch():
|
||||||
|
|
|
@ -388,6 +388,8 @@ Library
|
||||||
- Issue #28399: Remove UNIX socket from FS before binding.
|
- Issue #28399: Remove UNIX socket from FS before binding.
|
||||||
Patch by Коренберг Марк.
|
Patch by Коренберг Марк.
|
||||||
|
|
||||||
|
- Issue #27972: Prohibit Tasks to await on themselves.
|
||||||
|
|
||||||
IDLE
|
IDLE
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue