Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
20cd54fc
Commit
20cd54fc
authored
Dec 06, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow resetting and ignoring SIGCHLD. Fixes #696.
parent
c257a0d9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
1 deletion
+56
-1
changelog.rst
changelog.rst
+4
-1
gevent/signal.py
gevent/signal.py
+10
-0
greentest/test__monkey_sigchld_2.py
greentest/test__monkey_sigchld_2.py
+42
-0
No files found.
changelog.rst
View file @
20cd54fc
...
...
@@ -16,7 +16,10 @@
``sendall``.
- gevent's SSL socket's ``sendall`` method should no longer raise ``SSL3_WRITE_PENDING``
in rare cases when sending large buffers. Reported in :issue:`317`.
- ``gevent.signal`` now allows resetting (SIG_DFL) and ignoring (SIG_IGN) the
SIGCHLD signal at the process level (although this may allow race
conditions with libev child watchers). Reported in :issue:`696` by
Adam Ning.
1.1rc1 (Nov 14, 2015)
=====================
...
...
gevent/signal.py
View file @
20cd54fc
...
...
@@ -61,6 +61,11 @@ def signal(signalnum, handler):
the builtin :func:`signal.signal` would be triggered either;
libev typically overwrites such a handler at the C level. At
the very least, it's full of race conditions.)
.. note::
Use of ``SIG_IGN`` and ``SIG_DFL`` may also have race conditions
with libev child watchers and the :mod:`gevent.subprocess` module.
"""
if
signalnum
!=
_signal
.
SIGCHLD
:
return
_signal_signal
(
signalnum
,
handler
)
...
...
@@ -75,6 +80,11 @@ def signal(signalnum, handler):
old_handler
=
getsignal
(
signalnum
)
global
_child_handler
_child_handler
=
handler
if
handler
==
_signal
.
SIG_IGN
or
handler
==
_signal
.
SIG_DFL
:
# Allow resetting/ignoring this signal at the process level.
# Note that this conflicts with gevent.subprocess and other users
# of child watchers.
_signal_signal
(
signalnum
,
handler
)
return
old_handler
...
...
greentest/test__monkey_sigchld_2.py
0 → 100644
View file @
20cd54fc
# Mimics what gunicorn workers do: monkey patch in the child process
# and try to reset signal handlers to SIG_DFL.
# NOTE: This breaks again when gevent.subprocess is used, or any child
# watcher.
import
os
import
sys
import
signal
def
handle
(
*
args
):
if
not
pid
:
# We only do this is the child so our
# parent's waitpid can get the status.
# This is the opposite of gunicorn.
os
.
waitpid
(
-
1
,
os
.
WNOHANG
)
# The signal watcher must be installed *before* monkey patching
signal
.
signal
(
signal
.
SIGCHLD
,
handle
)
pid
=
os
.
fork
()
if
pid
:
# parent
try
:
_
,
stat
=
os
.
waitpid
(
pid
,
0
)
except
OSError
:
# Interrupted system call
_
,
stat
=
os
.
waitpid
(
pid
,
0
)
assert
stat
==
0
,
stat
else
:
import
gevent.monkey
gevent
.
monkey
.
patch_all
()
signal
.
signal
(
signal
.
SIGCHLD
,
signal
.
SIG_DFL
)
# Under Python 2, os.popen() directly uses the popen call, and
# popen's file uses the pclose() system call to
# wait for the child. If it's already waited on,
# it raises the same exception.
# Python 3 uses the subprocess module directly which doesn't
# have this problem.
f
=
os
.
popen
(
'true'
)
f
.
close
()
sys
.
exit
(
0
)
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