Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
52bca3e7
Commit
52bca3e7
authored
Oct 09, 2016
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #27972: Prohibit Tasks to await on themselves.
parent
1e281477
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
7 deletions
+27
-7
Lib/asyncio/tasks.py
Lib/asyncio/tasks.py
+14
-7
Lib/test/test_asyncio/test_tasks.py
Lib/test/test_asyncio/test_tasks.py
+11
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/asyncio/tasks.py
View file @
52bca3e7
...
...
@@ -241,7 +241,7 @@ class Task(futures.Future):
result
=
coro
.
throw
(
exc
)
except
StopIteration
as
exc
:
self
.
set_result
(
exc
.
value
)
except
futures
.
CancelledError
as
exc
:
except
futures
.
CancelledError
:
super
().
cancel
()
# I.e., Future.cancel(self).
except
Exception
as
exc
:
self
.
set_exception
(
exc
)
...
...
@@ -259,12 +259,19 @@ class Task(futures.Future):
'Task {!r} got Future {!r} attached to a '
'different loop'
.
format
(
self
,
result
)))
elif
blocking
:
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
if
result
is
self
:
self
.
_loop
.
call_soon
(
self
.
_step
,
RuntimeError
(
'Task cannot await on itself: {!r}'
.
format
(
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
:
self
.
_loop
.
call_soon
(
self
.
_step
,
...
...
Lib/test/test_asyncio/test_tasks.py
View file @
52bca3e7
...
...
@@ -92,6 +92,17 @@ class TaskTests(test_utils.TestCase):
finally
:
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
):
@
asyncio
.
coroutine
def
notmuch
():
...
...
Misc/NEWS
View file @
52bca3e7
...
...
@@ -388,6 +388,8 @@ Library
-
Issue
#
28399
:
Remove
UNIX
socket
from
FS
before
binding
.
Patch
by
Коренберг
Марк
.
-
Issue
#
27972
:
Prohibit
Tasks
to
await
on
themselves
.
IDLE
----
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment