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
134a8bae
Kaydet (Commit)
134a8bae
authored
Agu 18, 2011
tarafından
Charles-François Natali
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #12650: Fix a race condition where a subprocess.Popen could leak
resources (FD/zombie) when killed at the wrong time.
üst
5ad517a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
1 deletion
+69
-1
subprocess.py
Lib/subprocess.py
+6
-1
test_subprocess.py
Lib/test/test_subprocess.py
+58
-0
NEWS
Misc/NEWS
+5
-0
No files found.
Lib/subprocess.py
Dosyayı görüntüle @
134a8bae
...
...
@@ -429,12 +429,16 @@ try:
except
:
MAXFD
=
256
# This lists holds Popen instances for which the underlying process had not
# exited at the time its __del__ method got called: those processes are wait()ed
# for synchronously from _cleanup() when a new Popen object is created, to avoid
# zombie processes.
_active
=
[]
def
_cleanup
():
for
inst
in
_active
[:]:
res
=
inst
.
_internal_poll
(
_deadstate
=
sys
.
maxsize
)
if
res
is
not
None
and
res
>=
0
:
if
res
is
not
None
:
try
:
_active
.
remove
(
inst
)
except
ValueError
:
...
...
@@ -1191,6 +1195,7 @@ class Popen(object):
errread
,
errwrite
,
errpipe_read
,
errpipe_write
,
restore_signals
,
start_new_session
,
preexec_fn
)
self
.
_child_created
=
True
else
:
# Pure Python implementation: It is not thread safe.
# This implementation may deadlock in the child if your
...
...
Lib/test/test_subprocess.py
Dosyayı görüntüle @
134a8bae
...
...
@@ -1394,6 +1394,64 @@ class POSIXProcessTestCase(BaseTestCase):
finally
:
p
.
wait
()
def
test_zombie_fast_process_del
(
self
):
# Issue #12650: on Unix, if Popen.__del__() was called before the
# process exited, it wouldn't be added to subprocess._active, and would
# remain a zombie.
# spawn a Popen, and delete its reference before it exits
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'import sys, time;'
'time.sleep(0.2)'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
ident
=
id
(
p
)
pid
=
p
.
pid
del
p
# check that p is in the active processes list
self
.
assertIn
(
ident
,
[
id
(
o
)
for
o
in
subprocess
.
_active
])
# sleep a little to let the process exit, and create a new Popen: this
# should trigger the wait() of p
time
.
sleep
(
1
)
with
self
.
assertRaises
(
EnvironmentError
)
as
c
:
with
subprocess
.
Popen
([
'nonexisting_i_hope'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
as
proc
:
pass
# p should have been wait()ed on, and removed from the _active list
self
.
assertRaises
(
OSError
,
os
.
waitpid
,
pid
,
0
)
self
.
assertNotIn
(
ident
,
[
id
(
o
)
for
o
in
subprocess
.
_active
])
def
test_leak_fast_process_del_killed
(
self
):
# Issue #12650: on Unix, if Popen.__del__() was called before the
# process exited, and the process got killed by a signal, it would never
# be removed from subprocess._active, which triggered a FD and memory
# leak.
# spawn a Popen, delete its reference and kill it
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'import time;'
'time.sleep(3)'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
ident
=
id
(
p
)
pid
=
p
.
pid
del
p
os
.
kill
(
pid
,
signal
.
SIGKILL
)
# check that p is in the active processes list
self
.
assertIn
(
ident
,
[
id
(
o
)
for
o
in
subprocess
.
_active
])
# let some time for the process to exit, and create a new Popen: this
# should trigger the wait() of p
time
.
sleep
(
0.2
)
with
self
.
assertRaises
(
EnvironmentError
)
as
c
:
with
subprocess
.
Popen
([
'nonexisting_i_hope'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
as
proc
:
pass
# p should have been wait()ed on, and removed from the _active list
self
.
assertRaises
(
OSError
,
os
.
waitpid
,
pid
,
0
)
self
.
assertNotIn
(
ident
,
[
id
(
o
)
for
o
in
subprocess
.
_active
])
@unittest.skipUnless
(
mswindows
,
"Windows specific tests"
)
class
Win32ProcessTestCase
(
BaseTestCase
):
...
...
Misc/NEWS
Dosyayı görüntüle @
134a8bae
...
...
@@ -13,6 +13,11 @@ Core and Builtins
- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase
titlecased and cased non-letter characters.
Library
-------
- Issue #12650: Fix a race condition where a subprocess.Popen could leak
resources (FD/zombie) when killed at the wrong time.
What's New in Python 3.2.2?
===========================
...
...
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