[Jython-checkins] jython: More robust registering/raising of signals on JVMs other than OpenJDK
jim.baker
jython-checkins at python.org
Sun Feb 22 18:40:13 CET 2015
https://hg.python.org/jython/rev/e909a4641731
changeset: 7597:e909a4641731
user: Pekka Klärck <peke at iki.fi>
date: Sun Feb 22 10:40:10 2015 -0700
summary:
More robust registering/raising of signals on JVMs other than OpenJDK
Certain platforms, such as IBM's J9, raise
java.lang.IllegalArgumentException when attempting to register or
raise signals, even when present as determined by Jython's signal
probe. Raise ValueError in these cases.
Fixes http://bugs.jython.org/issue1729
files:
Lib/signal.py | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/Lib/signal.py b/Lib/signal.py
--- a/Lib/signal.py
+++ b/Lib/signal.py
@@ -132,9 +132,9 @@
raise ValueError("signal number out of range")
if callable(action):
- prev = sun.misc.Signal.handle(signal, JythonSignalHandler(action))
+ prev = _register_signal(signal, JythonSignalHandler(action))
elif action in (SIG_IGN, SIG_DFL) or isinstance(action, sun.misc.SignalHandler):
- prev = sun.misc.Signal.handle(signal, action)
+ prev = _register_signal(signal, action)
else:
raise TypeError("signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object")
@@ -144,6 +144,13 @@
return prev
+def _register_signal(signal, action):
+ try:
+ return sun.misc.Signal.handle(signal, action)
+ except IllegalArgumentException, err:
+ raise ValueError(err.getMessage())
+
+
# dangerous! don't use!
def getsignal(sig):
"""getsignal(sig) -> action
@@ -162,8 +169,8 @@
signal = _signals[sig]
except KeyError:
raise ValueError("signal number out of range")
- current = sun.misc.Signal.handle(signal, SIG_DFL)
- sun.misc.Signal.handle(signal, current) # and reinstall
+ current = _register_signal(signal, SIG_DFL)
+ _register_signal(signal, current) # and reinstall
if isinstance(current, JythonSignalHandler):
return current.action
@@ -222,7 +229,10 @@
raise NotImplementedError("alarm not implemented on this platform")
def raise_alarm():
- sun.misc.Signal.raise(_signals[SIGALRM])
+ try:
+ sun.misc.Signal.raise(_signals[SIGALRM])
+ except IllegalArgumentException, err:
+ raise ValueError(err.getMessage())
if time > 0:
new_alarm_timer = _Alarm(time, raise_alarm)
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list