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
ba7e1f9a
Commit
ba7e1f9a
authored
Mar 02, 2017
by
Yury Selivanov
Committed by
GitHub
Mar 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29703: asyncio: Fix creating new event loops in child processes. (#404)
parent
cdf037c2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
2 deletions
+36
-2
Lib/asyncio/events.py
Lib/asyncio/events.py
+7
-1
Lib/asyncio/test_utils.py
Lib/asyncio/test_utils.py
+4
-1
Lib/test/test_asyncio/test_events.py
Lib/test/test_asyncio/test_events.py
+22
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/asyncio/events.py
View file @
ba7e1f9a
...
...
@@ -11,6 +11,7 @@ __all__ = ['AbstractEventLoopPolicy',
import
functools
import
inspect
import
os
import
reprlib
import
socket
import
subprocess
...
...
@@ -611,6 +612,9 @@ _lock = threading.Lock()
# A TLS for the running event loop, used by _get_running_loop.
class
_RunningLoop
(
threading
.
local
):
_loop
=
None
_pid
=
None
_running_loop
=
_RunningLoop
()
...
...
@@ -620,7 +624,8 @@ def _get_running_loop():
This is a low-level function intended to be used by event loops.
This function is thread-specific.
"""
return
_running_loop
.
_loop
if
_running_loop
.
_pid
==
os
.
getpid
():
return
_running_loop
.
_loop
def
_set_running_loop
(
loop
):
...
...
@@ -629,6 +634,7 @@ def _set_running_loop(loop):
This is a low-level function intended to be used by event loops.
This function is thread-specific.
"""
_running_loop
.
_pid
=
os
.
getpid
()
_running_loop
.
_loop
=
loop
...
...
Lib/asyncio/test_utils.py
View file @
ba7e1f9a
...
...
@@ -449,12 +449,15 @@ class TestCase(unittest.TestCase):
self
.
set_event_loop
(
loop
)
return
loop
def
unpatch_get_running_loop
(
self
):
events
.
_get_running_loop
=
self
.
_get_running_loop
def
setUp
(
self
):
self
.
_get_running_loop
=
events
.
_get_running_loop
events
.
_get_running_loop
=
lambda
:
None
def
tearDown
(
self
):
events
.
_get_running_loop
=
self
.
_get_running_loop
self
.
unpatch_get_running_loop
()
events
.
set_event_loop
(
None
)
...
...
Lib/test/test_asyncio/test_events.py
View file @
ba7e1f9a
"""Tests for events.py."""
import
collections.abc
import
concurrent.futures
import
functools
import
gc
import
io
...
...
@@ -57,6 +58,15 @@ def osx_tiger():
return
version
<
(
10
,
5
)
def
_test_get_event_loop_new_process__sub_proc
():
async
def
doit
():
return
'hello'
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
loop
)
return
loop
.
run_until_complete
(
doit
())
ONLYCERT
=
data_file
(
'ssl_cert.pem'
)
ONLYKEY
=
data_file
(
'ssl_key.pem'
)
SIGNED_CERTFILE
=
data_file
(
'keycert3.pem'
)
...
...
@@ -2181,6 +2191,18 @@ else:
asyncio
.
set_child_watcher
(
None
)
super
().
tearDown
()
def
test_get_event_loop_new_process
(
self
):
async
def
main
():
pool
=
concurrent
.
futures
.
ProcessPoolExecutor
()
return
await
self
.
loop
.
run_in_executor
(
pool
,
_test_get_event_loop_new_process__sub_proc
)
self
.
unpatch_get_running_loop
()
self
.
assertEqual
(
self
.
loop
.
run_until_complete
(
main
()),
'hello'
)
if
hasattr
(
selectors
,
'KqueueSelector'
):
class
KqueueEventLoopTests
(
UnixEventLoopTestsMixin
,
SubprocessTestsMixin
,
...
...
Misc/NEWS
View file @
ba7e1f9a
...
...
@@ -256,6 +256,9 @@ Extension Modules
Library
-------
-
bpo
-
29703
:
Fix
asyncio
to
support
instantiation
of
new
event
loops
in
child
processes
.
-
bpo
-
29615
:
SimpleXMLRPCDispatcher
no
longer
chains
KeyError
(
or
any
other
exception
)
to
exception
(
s
)
raised
in
the
dispatched
methods
.
Patch
by
Petr
Motejlek
.
...
...
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