summaryrefslogtreecommitdiff
path: root/Lib/test/test_signal.py
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2008-02-23 15:07:35 +0000
committerFacundo Batista <facundobatista@gmail.com>2008-02-23 15:07:35 +0000
commit7e251e83d5b488904212f91bace1322d12475803 (patch)
tree29f24e91e6a5261772816d5b500937b59e9a819d /Lib/test/test_signal.py
parent57826cf9f8c1d75da8d7d0e27f564adb441329ad (diff)
downloadcpython-git-7e251e83d5b488904212f91bace1322d12475803.tar.gz
Issue 1089358. Adds the siginterrupt() function, that is just a
wrapper around the system call with the same name. Also added test cases, doc changes and NEWS entry. Thanks Jason and Ralf Schmitt.
Diffstat (limited to 'Lib/test/test_signal.py')
-rw-r--r--Lib/test/test_signal.py48
1 files changed, 46 insertions, 2 deletions
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index 8cf82f4a8d..332001f6a2 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -1,7 +1,7 @@
import unittest
from test import test_support
import signal
-import os, sys, time
+import os, sys, time, errno
class HandlerBCalled(Exception):
pass
@@ -210,6 +210,50 @@ class WakeupSignalTests(unittest.TestCase):
os.close(self.write)
signal.signal(signal.SIGALRM, self.alrm)
+class SiginterruptTest(unittest.TestCase):
+ signum = signal.SIGUSR1
+ def readpipe_interrupted(self, cb):
+ r, w = os.pipe()
+ ppid = os.getpid()
+ pid = os.fork()
+
+ oldhandler = signal.signal(self.signum, lambda x,y: None)
+ cb()
+ if pid==0:
+ # child code: sleep, kill, sleep. and then exit,
+ # which closes the pipe from which the parent process reads
+ try:
+ time.sleep(0.2)
+ os.kill(ppid, self.signum)
+ time.sleep(0.2)
+ finally:
+ os._exit(0)
+
+ try:
+ os.close(w)
+
+ try:
+ d=os.read(r, 1)
+ return False
+ except OSError, err:
+ if err.errno != errno.EINTR:
+ raise
+ return True
+ finally:
+ signal.signal(self.signum, oldhandler)
+ os.waitpid(pid, 0)
+
+ def test_without_siginterrupt(self):
+ i=self.readpipe_interrupted(lambda: None)
+ self.assertEquals(i, True)
+
+ def test_siginterrupt_on(self):
+ i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 1))
+ self.assertEquals(i, True)
+
+ def test_siginterrupt_off(self):
+ i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 0))
+ self.assertEquals(i, False)
def test_main():
if sys.platform[:3] in ('win', 'os2') or sys.platform == 'riscos':
@@ -217,7 +261,7 @@ def test_main():
sys.platform)
test_support.run_unittest(BasicSignalTests, InterProcessSignalTests,
- WakeupSignalTests)
+ WakeupSignalTests, SiginterruptTest)
if __name__ == "__main__":