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
1bb8109f
Kaydet (Commit)
1bb8109f
authored
Haz 03, 2016
tarafından
Gregory P. Smith ext:(%20%5BGoogle%20Inc.%5D)
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Reindent properly.
üst
cef1f83c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
76 deletions
+74
-76
socketserver.py
Lib/socketserver.py
+74
-76
No files found.
Lib/socketserver.py
Dosyayı görüntüle @
1bb8109f
...
...
@@ -540,87 +540,85 @@ class UDPServer(TCPServer):
pass
if
hasattr
(
os
,
"fork"
):
# Non-standard indentation on this statement to avoid reindenting the body.
class
ForkingMixIn
:
class
ForkingMixIn
:
"""Mix-in class to handle each request in a new process."""
"""Mix-in class to handle each request in a new process."""
timeout
=
300
active_children
=
None
max_children
=
40
timeout
=
300
active_children
=
None
max_children
=
40
def
collect_children
(
self
):
"""Internal routine to wait for children that have exited."""
if
self
.
active_children
is
None
:
return
# If we're above the max number of children, wait and reap them until
# we go back below threshold. Note that we use waitpid(-1) below to be
# able to collect children in size(<defunct children>) syscalls instead
# of size(<children>): the downside is that this might reap children
# which we didn't spawn, which is why we only resort to this when we're
# above max_children.
while
len
(
self
.
active_children
)
>=
self
.
max_children
:
try
:
pid
,
_
=
os
.
waitpid
(
-
1
,
0
)
self
.
active_children
.
discard
(
pid
)
except
ChildProcessError
:
# we don't have any children, we're done
self
.
active_children
.
clear
()
except
OSError
:
break
# Now reap all defunct children.
for
pid
in
self
.
active_children
.
copy
():
try
:
pid
,
_
=
os
.
waitpid
(
pid
,
os
.
WNOHANG
)
# if the child hasn't exited yet, pid will be 0 and ignored by
# discard() below
self
.
active_children
.
discard
(
pid
)
except
ChildProcessError
:
# someone else reaped it
self
.
active_children
.
discard
(
pid
)
except
OSError
:
pass
def
handle_timeout
(
self
):
"""Wait for zombies after self.timeout seconds of inactivity.
May be extended, do not override.
"""
self
.
collect_children
()
def
service_actions
(
self
):
"""Collect the zombie child processes regularly in the ForkingMixIn.
service_actions is called in the BaseServer's serve_forver loop.
"""
self
.
collect_children
()
def
process_request
(
self
,
request
,
client_address
):
"""Fork a new subprocess to process the request."""
pid
=
os
.
fork
()
if
pid
:
# Parent process
def
collect_children
(
self
):
"""Internal routine to wait for children that have exited."""
if
self
.
active_children
is
None
:
self
.
active_children
=
set
()
self
.
active_children
.
add
(
pid
)
self
.
close_request
(
request
)
return
else
:
# Child process.
# This must never return, hence os._exit()!
status
=
1
try
:
self
.
finish_request
(
request
,
client_address
)
status
=
0
except
Exception
:
self
.
handle_error
(
request
,
client_address
)
finally
:
return
# If we're above the max number of children, wait and reap them until
# we go back below threshold. Note that we use waitpid(-1) below to be
# able to collect children in size(<defunct children>) syscalls instead
# of size(<children>): the downside is that this might reap children
# which we didn't spawn, which is why we only resort to this when we're
# above max_children.
while
len
(
self
.
active_children
)
>=
self
.
max_children
:
try
:
pid
,
_
=
os
.
waitpid
(
-
1
,
0
)
self
.
active_children
.
discard
(
pid
)
except
ChildProcessError
:
# we don't have any children, we're done
self
.
active_children
.
clear
()
except
OSError
:
break
# Now reap all defunct children.
for
pid
in
self
.
active_children
.
copy
():
try
:
pid
,
_
=
os
.
waitpid
(
pid
,
os
.
WNOHANG
)
# if the child hasn't exited yet, pid will be 0 and ignored by
# discard() below
self
.
active_children
.
discard
(
pid
)
except
ChildProcessError
:
# someone else reaped it
self
.
active_children
.
discard
(
pid
)
except
OSError
:
pass
def
handle_timeout
(
self
):
"""Wait for zombies after self.timeout seconds of inactivity.
May be extended, do not override.
"""
self
.
collect_children
()
def
service_actions
(
self
):
"""Collect the zombie child processes regularly in the ForkingMixIn.
service_actions is called in the BaseServer's serve_forver loop.
"""
self
.
collect_children
()
def
process_request
(
self
,
request
,
client_address
):
"""Fork a new subprocess to process the request."""
pid
=
os
.
fork
()
if
pid
:
# Parent process
if
self
.
active_children
is
None
:
self
.
active_children
=
set
()
self
.
active_children
.
add
(
pid
)
self
.
close_request
(
request
)
return
else
:
# Child process.
# This must never return, hence os._exit()!
status
=
1
try
:
self
.
shutdown_request
(
request
)
self
.
finish_request
(
request
,
client_address
)
status
=
0
except
Exception
:
self
.
handle_error
(
request
,
client_address
)
finally
:
os
.
_exit
(
status
)
try
:
self
.
shutdown_request
(
request
)
finally
:
os
.
_exit
(
status
)
class
ThreadingMixIn
:
...
...
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