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
9eb6c677
Kaydet (Commit)
9eb6c677
authored
Eki 05, 2016
tarafından
Yury Selivanov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28368: Refuse monitoring processes if the child watcher has no loop attached.
Patch by Vincent Michel.
üst
b5bb404c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
6 deletions
+42
-6
unix_events.py
Lib/asyncio/unix_events.py
+18
-5
test_subprocess.py
Lib/test/test_asyncio/test_subprocess.py
+7
-0
test_unix_events.py
Lib/test/test_asyncio/test_unix_events.py
+13
-1
NEWS
Misc/NEWS
+4
-0
No files found.
Lib/asyncio/unix_events.py
Dosyayı görüntüle @
9eb6c677
...
...
@@ -746,6 +746,7 @@ class BaseChildWatcher(AbstractChildWatcher):
def
__init__
(
self
):
self
.
_loop
=
None
self
.
_callbacks
=
{}
def
close
(
self
):
self
.
attach_loop
(
None
)
...
...
@@ -759,6 +760,12 @@ class BaseChildWatcher(AbstractChildWatcher):
def
attach_loop
(
self
,
loop
):
assert
loop
is
None
or
isinstance
(
loop
,
events
.
AbstractEventLoop
)
if
self
.
_loop
is
not
None
and
loop
is
None
and
self
.
_callbacks
:
warnings
.
warn
(
'A loop is being detached '
'from a child watcher with pending handlers'
,
RuntimeWarning
)
if
self
.
_loop
is
not
None
:
self
.
_loop
.
remove_signal_handler
(
signal
.
SIGCHLD
)
...
...
@@ -807,10 +814,6 @@ class SafeChildWatcher(BaseChildWatcher):
big number of children (O(n) each time SIGCHLD is raised)
"""
def
__init__
(
self
):
super
()
.
__init__
()
self
.
_callbacks
=
{}
def
close
(
self
):
self
.
_callbacks
.
clear
()
super
()
.
close
()
...
...
@@ -822,6 +825,11 @@ class SafeChildWatcher(BaseChildWatcher):
pass
def
add_child_handler
(
self
,
pid
,
callback
,
*
args
):
if
self
.
_loop
is
None
:
raise
RuntimeError
(
"Cannot add child handler, "
"the child watcher does not have a loop attached"
)
self
.
_callbacks
[
pid
]
=
(
callback
,
args
)
# Prevent a race condition in case the child is already terminated.
...
...
@@ -886,7 +894,6 @@ class FastChildWatcher(BaseChildWatcher):
"""
def
__init__
(
self
):
super
()
.
__init__
()
self
.
_callbacks
=
{}
self
.
_lock
=
threading
.
Lock
()
self
.
_zombies
=
{}
self
.
_forks
=
0
...
...
@@ -918,6 +925,12 @@ class FastChildWatcher(BaseChildWatcher):
def
add_child_handler
(
self
,
pid
,
callback
,
*
args
):
assert
self
.
_forks
,
"Must use the context manager"
if
self
.
_loop
is
None
:
raise
RuntimeError
(
"Cannot add child handler, "
"the child watcher does not have a loop attached"
)
with
self
.
_lock
:
try
:
returncode
=
self
.
_zombies
.
pop
(
pid
)
...
...
Lib/test/test_asyncio/test_subprocess.py
Dosyayı görüntüle @
9eb6c677
...
...
@@ -433,6 +433,13 @@ class SubprocessMixin:
# the transport was not notified yet
self
.
assertFalse
(
killed
)
# Unlike SafeChildWatcher, FastChildWatcher does not pop the
# callbacks if waitpid() is called elsewhere. Let's clear them
# manually to avoid a warning when the watcher is detached.
if
sys
.
platform
!=
'win32'
and
\
isinstance
(
self
,
SubprocessFastWatcherTests
):
asyncio
.
get_child_watcher
()
.
_callbacks
.
clear
()
def
test_popen_error
(
self
):
# Issue #24763: check that the subprocess transport is closed
# when BaseSubprocessTransport fails
...
...
Lib/test/test_asyncio/test_unix_events.py
Dosyayı görüntüle @
9eb6c677
...
...
@@ -11,6 +11,7 @@ import sys
import
tempfile
import
threading
import
unittest
import
warnings
from
unittest
import
mock
if
sys
.
platform
==
'win32'
:
...
...
@@ -1391,7 +1392,9 @@ class ChildWatcherTestsMixin:
with
mock
.
patch
.
object
(
old_loop
,
"remove_signal_handler"
)
as
m_remove_signal_handler
:
self
.
watcher
.
attach_loop
(
None
)
with
self
.
assertWarnsRegex
(
RuntimeWarning
,
'A loop is being detached'
):
self
.
watcher
.
attach_loop
(
None
)
m_remove_signal_handler
.
assert_called_once_with
(
signal
.
SIGCHLD
)
...
...
@@ -1463,6 +1466,15 @@ class ChildWatcherTestsMixin:
if
isinstance
(
self
.
watcher
,
asyncio
.
FastChildWatcher
):
self
.
assertFalse
(
self
.
watcher
.
_zombies
)
@waitpid_mocks
def
test_add_child_handler_with_no_loop_attached
(
self
,
m
):
callback
=
mock
.
Mock
()
with
self
.
create_watcher
()
as
watcher
:
with
self
.
assertRaisesRegex
(
RuntimeError
,
'the child watcher does not have a loop attached'
):
watcher
.
add_child_handler
(
100
,
callback
)
class
SafeChildWatcherTests
(
ChildWatcherTestsMixin
,
test_utils
.
TestCase
):
def
create_watcher
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
9eb6c677
...
...
@@ -346,6 +346,10 @@ Library
- Issue #27759: Fix selectors incorrectly retain invalid file descriptors.
Patch by Mark Williams.
- Issue #28368: Refuse monitoring processes if the child watcher has
no loop attached.
Patch by Vincent Michel.
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