diff options
author | Michael W. Hudson <mwh@python.net> | 2002-05-27 15:08:24 (GMT) |
---|---|---|
committer | Michael W. Hudson <mwh@python.net> | 2002-05-27 15:08:24 (GMT) |
commit | 34f20eac987b1ca006ebdfe5531a6931243294fb (patch) | |
tree | c1ffdc5009d7b8f4720dd035a98e2e9af46141c7 /Lib/test | |
parent | e5df1058f12b254bb0958ed7ebf788c0eb6fa332 (diff) | |
download | cpython-34f20eac987b1ca006ebdfe5531a6931243294fb.zip cpython-34f20eac987b1ca006ebdfe5531a6931243294fb.tar.gz cpython-34f20eac987b1ca006ebdfe5531a6931243294fb.tar.bz2 |
This is patch
[ 559250 ] more POSIX signal stuff
Adds support (and docs and tests and autoconfery) for posix signal
mask handling -- sigpending, sigprocmask and sigsuspend.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_signal.py | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index 05bdcab..78b90b7 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -1,8 +1,7 @@ # Test the signal module -from test_support import verbose, TestSkipped +from test_support import verbose, TestSkipped, TestFailed import signal -import os -import sys +import os, sys, time if sys.platform[:3] in ('win', 'os2') or sys.platform=='riscos': raise TestSkipped, "Can't test signal on %s" % sys.platform @@ -64,3 +63,66 @@ try: except KeyboardInterrupt: if verbose: print "KeyboardInterrupt (assume the alarm() went off)" + + +if hasattr(signal, "sigprocmask"): + class HupDelivered(Exception): + pass + def hup(signum, frame): + raise HupDelivered + def hup2(signum, frame): + signal.signal(signal.SIGHUP, hup) + return + signal.signal(signal.SIGHUP, hup) + + if verbose: + print "blocking SIGHUP" + + defaultmask = signal.sigprocmask(signal.SIG_BLOCK, [signal.SIGHUP]) + + if verbose: + print "sending SIGHUP" + + try: + os.kill(pid, signal.SIGHUP) + except HupDelivered: + raise TestFailed, "HUP not blocked" + + if signal.SIGHUP not in signal.sigpending(): + raise TestFailed, "HUP not pending" + + if verbose: + print "unblocking SIGHUP" + + try: + signal.sigprocmask(signal.SIG_UNBLOCK, [signal.SIGHUP]) + except HupDelivered: + pass + else: + raise TestFailed, "HUP not delivered" + + if verbose: + print "testing sigsuspend" + + signal.sigprocmask(signal.SIG_BLOCK, [signal.SIGHUP]) + signal.signal(signal.SIGHUP, hup2) + + if not os.fork(): + time.sleep(2) + os.kill(pid, signal.SIGHUP) + time.sleep(2) + os.kill(pid, signal.SIGHUP) + os._exit(0) + else: + try: + signal.sigsuspend(defaultmask) + except: + raise TestFailed, "sigsuspend erroneously raised" + + try: + signal.sigsuspend(defaultmask) + except HupDelivered: + pass + else: + raise TestFailed, "sigsupsend didn't raise" + |