diff options
author | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-04-02 04:07:44 (GMT) |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-04-02 04:07:44 (GMT) |
commit | ab561317203121ffda9841f84572ecdab68a84d6 (patch) | |
tree | 1da7eb60f323f8eb233450aaa918867b36b3ec33 /Lib/test/test_signal.py | |
parent | cb0f2ad0c2f45ae065ce87c27080355a98965042 (diff) | |
download | cpython-ab561317203121ffda9841f84572ecdab68a84d6.zip cpython-ab561317203121ffda9841f84572ecdab68a84d6.tar.gz cpython-ab561317203121ffda9841f84572ecdab68a84d6.tar.bz2 |
Try to make test_signal less flaky. I still see some flakiness in
test_itimer_prof.
Diffstat (limited to 'Lib/test/test_signal.py')
-rw-r--r-- | Lib/test/test_signal.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index 198845c..acb8e57 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -28,6 +28,15 @@ def exit_subprocess(): os._exit(0) +def ignoring_eintr(__func, *args, **kwargs): + try: + return __func(*args, **kwargs) + except IOError as e: + if e.errno != signal.EINTR: + raise + return None + + class InterProcessSignalTests(unittest.TestCase): MAX_DURATION = 20 # Entire test should last at most 20 sec. @@ -77,8 +86,11 @@ class InterProcessSignalTests(unittest.TestCase): if test_support.verbose: print "test runner's pid is", pid - child = subprocess.Popen(['kill', '-HUP', str(pid)]) - self.wait(child) + child = ignoring_eintr(subprocess.Popen, ['kill', '-HUP', str(pid)]) + if child: + self.wait(child) + if not self.a_called: + time.sleep(1) # Give the signal time to be delivered. self.assertTrue(self.a_called) self.assertFalse(self.b_called) self.a_called = False @@ -87,6 +99,7 @@ class InterProcessSignalTests(unittest.TestCase): child = subprocess.Popen(['kill', '-USR1', str(pid)]) # This wait should be interrupted by the signal's exception. self.wait(child) + time.sleep(1) # Give the signal time to be delivered. self.fail('HandlerBCalled exception not thrown') except HandlerBCalled: self.assertTrue(self.b_called) @@ -94,8 +107,9 @@ class InterProcessSignalTests(unittest.TestCase): if test_support.verbose: print "HandlerBCalled exception caught" - child = subprocess.Popen(['kill', '-USR2', str(pid)]) - self.wait(child) # Nothing should happen. + child = ignoring_eintr(subprocess.Popen, ['kill', '-USR2', str(pid)]) + if child: + self.wait(child) # Nothing should happen. try: signal.alarm(1) @@ -103,14 +117,18 @@ class InterProcessSignalTests(unittest.TestCase): # since alarm is going to raise a KeyboardException, which # will skip the call. signal.pause() + # But if another signal arrives before the alarm, pause + # may return early. + time.sleep(1) except KeyboardInterrupt: if test_support.verbose: print "KeyboardInterrupt (the alarm() went off)" except: - self.fail('Some other exception woke us from pause: %s' % + self.fail("Some other exception woke us from pause: %s" % traceback.format_exc()) else: - self.fail('pause returned of its own accord') + self.fail("pause returned of its own accord, and the signal" + " didn't arrive after another second.") def test_main(self): # This function spawns a child process to insulate the main |