Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
5d97b7bc
Unverified
Kaydet (Commit)
5d97b7bc
authored
May 29, 2018
tarafından
Yury Selivanov
Kaydeden (comit)
GitHub
May 29, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-22087: Fix Policy.get_event_loop() to detect fork (GH-7208)
Original patch by Dan O'Reilly.
üst
e55de2d7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
0 deletions
+42
-0
events.py
Lib/asyncio/events.py
+7
-0
test_unix_events.py
Lib/test/test_asyncio/test_unix_events.py
+32
-0
2018-05-29-12-06-54.bpo-22087.uv7_Y6.rst
...S.d/next/Library/2018-05-29-12-06-54.bpo-22087.uv7_Y6.rst
+3
-0
No files found.
Lib/asyncio/events.py
Dosyayı görüntüle @
5d97b7bc
...
...
@@ -625,16 +625,23 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
class
_Local
(
threading
.
local
):
_loop
=
None
_pid
=
None
_set_called
=
False
def
__init__
(
self
):
self
.
_local
=
self
.
_Local
()
self
.
_local
.
_pid
=
os
.
getpid
()
def
get_event_loop
(
self
):
"""Get the event loop.
This may be None or an instance of EventLoop.
"""
if
self
.
_local
.
_pid
!=
os
.
getpid
():
# If we detect we're in a child process forked by multiprocessing,
# we reset self._local so that we'll get a new event loop.
self
.
_local
=
self
.
_Local
()
if
(
self
.
_local
.
_loop
is
None
and
not
self
.
_local
.
_set_called
and
isinstance
(
threading
.
current_thread
(),
threading
.
_MainThread
)):
...
...
Lib/test/test_asyncio/test_unix_events.py
Dosyayı görüntüle @
5d97b7bc
...
...
@@ -13,6 +13,7 @@ import sys
import
tempfile
import
threading
import
unittest
import
multiprocessing
from
unittest
import
mock
from
test
import
support
...
...
@@ -1804,6 +1805,37 @@ class FastChildWatcherTests (ChildWatcherTestsMixin, test_utils.TestCase):
return
asyncio
.
FastChildWatcher
()
class
ForkedProcessTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
parent_loop
=
asyncio
.
SelectorEventLoop
()
asyncio
.
set_event_loop
(
self
.
parent_loop
)
self
.
ctx
=
multiprocessing
.
get_context
(
"fork"
)
def
tearDown
(
self
):
self
.
parent_loop
.
close
()
def
_check_loops_not_equal
(
self
,
old_loop
):
loop
=
asyncio
.
get_event_loop
()
if
loop
is
old_loop
:
raise
RuntimeError
(
"Child process inherited parent's event loop"
)
try
:
val
=
loop
.
run_until_complete
(
asyncio
.
sleep
(
0.05
,
result
=
42
))
if
val
!=
42
:
raise
RuntimeError
(
"new event loop does not work"
)
finally
:
loop
.
close
()
sys
.
exit
(
loop
is
old_loop
)
def
test_new_loop_in_child
(
self
):
p
=
self
.
ctx
.
Process
(
target
=
self
.
_check_loops_not_equal
,
args
=
(
self
.
parent_loop
,))
p
.
start
()
p
.
join
()
self
.
assertEqual
(
p
.
exitcode
,
0
)
class
PolicyTests
(
unittest
.
TestCase
):
def
create_policy
(
self
):
...
...
Misc/NEWS.d/next/Library/2018-05-29-12-06-54.bpo-22087.uv7_Y6.rst
0 → 100644
Dosyayı görüntüle @
5d97b7bc
Fix Policy.get_event_loop() to detect fork and return a new loop.
Original patch by Dan O'Reilly.
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