Try to fix test_signal on FreeBSD. I'm assuming that os.kill is failing to
raise a signal, but switching to subprocess makes the code cleaner anyway.
This commit is contained in:
parent
859043c053
commit
413f588a36
|
@ -4,6 +4,7 @@ from contextlib import closing, nested
|
||||||
import pickle
|
import pickle
|
||||||
import select
|
import select
|
||||||
import signal
|
import signal
|
||||||
|
import subprocess
|
||||||
import traceback
|
import traceback
|
||||||
import sys, os, time, errno
|
import sys, os, time, errno
|
||||||
|
|
||||||
|
@ -40,15 +41,13 @@ class InterProcessSignalTests(unittest.TestCase):
|
||||||
print "handlerB invoked", args
|
print "handlerB invoked", args
|
||||||
raise HandlerBCalled(*args)
|
raise HandlerBCalled(*args)
|
||||||
|
|
||||||
def wait(self, child_pid):
|
def wait(self, child):
|
||||||
"""Wait for child_pid to finish, ignoring EINTR."""
|
"""Wait for child to finish, ignoring EINTR."""
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
os.waitpid(child_pid, 0)
|
child.wait()
|
||||||
return
|
return
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ECHILD:
|
|
||||||
return
|
|
||||||
if e.errno != errno.EINTR:
|
if e.errno != errno.EINTR:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -69,35 +68,24 @@ class InterProcessSignalTests(unittest.TestCase):
|
||||||
if test_support.verbose:
|
if test_support.verbose:
|
||||||
print "test runner's pid is", pid
|
print "test runner's pid is", pid
|
||||||
|
|
||||||
child = os.fork()
|
child = subprocess.Popen(['kill', '-HUP', str(pid)])
|
||||||
if child == 0:
|
|
||||||
os.kill(pid, signal.SIGHUP)
|
|
||||||
exit_subprocess()
|
|
||||||
self.wait(child)
|
self.wait(child)
|
||||||
self.assertTrue(self.a_called)
|
self.assertTrue(self.a_called)
|
||||||
self.assertFalse(self.b_called)
|
self.assertFalse(self.b_called)
|
||||||
self.a_called = False
|
self.a_called = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
child = os.fork()
|
child = subprocess.Popen(['kill', '-USR1', str(pid)])
|
||||||
if child == 0:
|
|
||||||
os.kill(pid, signal.SIGUSR1)
|
|
||||||
exit_subprocess()
|
|
||||||
# This wait should be interrupted by the signal's exception.
|
# This wait should be interrupted by the signal's exception.
|
||||||
self.wait(child)
|
self.wait(child)
|
||||||
self.fail('HandlerBCalled exception not thrown')
|
self.fail('HandlerBCalled exception not thrown')
|
||||||
except HandlerBCalled:
|
except HandlerBCalled:
|
||||||
# So we call it again to reap the child's zombie.
|
|
||||||
self.wait(child)
|
|
||||||
self.assertTrue(self.b_called)
|
self.assertTrue(self.b_called)
|
||||||
self.assertFalse(self.a_called)
|
self.assertFalse(self.a_called)
|
||||||
if test_support.verbose:
|
if test_support.verbose:
|
||||||
print "HandlerBCalled exception caught"
|
print "HandlerBCalled exception caught"
|
||||||
|
|
||||||
child = os.fork()
|
child = subprocess.Popen(['kill', '-USR2', str(pid)])
|
||||||
if child == 0:
|
|
||||||
os.kill(pid, signal.SIGUSR2)
|
|
||||||
exit_subprocess()
|
|
||||||
self.wait(child) # Nothing should happen.
|
self.wait(child) # Nothing should happen.
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue