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
8433fdbe
Commit
8433fdbe
authored
Sep 15, 2016
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asyncio: Sync with the upstream
parent
db9f3355
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
Lib/asyncio/base_events.py
Lib/asyncio/base_events.py
+60
-0
Lib/asyncio/events.py
Lib/asyncio/events.py
+4
-0
No files found.
Lib/asyncio/base_events.py
View file @
8433fdbe
...
...
@@ -28,6 +28,7 @@ import time
import
traceback
import
sys
import
warnings
import
weakref
from
.
import
compat
from
.
import
coroutines
...
...
@@ -242,6 +243,17 @@ class BaseEventLoop(events.AbstractEventLoop):
self
.
_task_factory
=
None
self
.
_coroutine_wrapper_set
=
False
if
hasattr
(
sys
,
'get_asyncgen_hooks'
):
# Python >= 3.6
# A weak set of all asynchronous generators that are
# being iterated by the loop.
self
.
_asyncgens
=
weakref
.
WeakSet
()
else
:
self
.
_asyncgens
=
None
# Set to True when `loop.shutdown_asyncgens` is called.
self
.
_asyncgens_shutdown_called
=
False
def
__repr__
(
self
):
return
(
'<%s running=%s closed=%s debug=%s>'
%
(
self
.
__class__
.
__name__
,
self
.
is_running
(),
...
...
@@ -333,6 +345,48 @@ class BaseEventLoop(events.AbstractEventLoop):
if
self
.
_closed
:
raise
RuntimeError
(
'Event loop is closed'
)
def
_asyncgen_finalizer_hook
(
self
,
agen
):
self
.
_asyncgens
.
discard
(
agen
)
if
not
self
.
is_closed
():
self
.
create_task
(
agen
.
aclose
())
def
_asyncgen_firstiter_hook
(
self
,
agen
):
if
self
.
_asyncgens_shutdown_called
:
warnings
.
warn
(
"asynchronous generator {!r} was scheduled after "
"loop.shutdown_asyncgens() call"
.
format
(
agen
),
ResourceWarning
,
source
=
self
)
self
.
_asyncgens
.
add
(
agen
)
@
coroutine
def
shutdown_asyncgens
(
self
):
"""Shutdown all active asynchronous generators."""
self
.
_asyncgens_shutdown_called
=
True
if
self
.
_asyncgens
is
None
or
not
len
(
self
.
_asyncgens
):
# If Python version is <3.6 or we don't have any asynchronous
# generators alive.
return
closing_agens
=
list
(
self
.
_asyncgens
)
self
.
_asyncgens
.
clear
()
shutdown_coro
=
tasks
.
gather
(
*
[
ag
.
aclose
()
for
ag
in
closing_agens
],
return_exceptions
=
True
,
loop
=
self
)
results
=
yield
from
shutdown_coro
for
result
,
agen
in
zip
(
results
,
closing_agens
):
if
isinstance
(
result
,
Exception
):
self
.
call_exception_handler
({
'message'
:
'an error occurred during closing of '
'asynchronous generator {!r}'
.
format
(
agen
),
'exception'
:
result
,
'asyncgen'
:
agen
})
def
run_forever
(
self
):
"""Run until stop() is called."""
self
.
_check_closed
()
...
...
@@ -340,6 +394,10 @@ class BaseEventLoop(events.AbstractEventLoop):
raise
RuntimeError
(
'Event loop is running.'
)
self
.
_set_coroutine_wrapper
(
self
.
_debug
)
self
.
_thread_id
=
threading
.
get_ident
()
if
self
.
_asyncgens
is
not
None
:
old_agen_hooks
=
sys
.
get_asyncgen_hooks
()
sys
.
set_asyncgen_hooks
(
firstiter
=
self
.
_asyncgen_firstiter_hook
,
finalizer
=
self
.
_asyncgen_finalizer_hook
)
try
:
while
True
:
self
.
_run_once
()
...
...
@@ -349,6 +407,8 @@ class BaseEventLoop(events.AbstractEventLoop):
self
.
_stopping
=
False
self
.
_thread_id
=
None
self
.
_set_coroutine_wrapper
(
False
)
if
self
.
_asyncgens
is
not
None
:
sys
.
set_asyncgen_hooks
(
*
old_agen_hooks
)
def
run_until_complete
(
self
,
future
):
"""Run until the Future is done.
...
...
Lib/asyncio/events.py
View file @
8433fdbe
...
...
@@ -248,6 +248,10 @@ class AbstractEventLoop:
"""
raise
NotImplementedError
def
shutdown_asyncgens
(
self
):
"""Shutdown all active asynchronous generators."""
raise
NotImplementedError
# Methods scheduling callbacks. All these return Handles.
def
_timer_handle_cancelled
(
self
,
handle
):
...
...
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