[Python-Dev] Python threads end up blocking signals in subprocesses
Jeff Epler
jepler at unpythonic.net
Wed Dec 17 18:31:26 EST 2003
On Wed, Dec 17, 2003 at 09:14:50AM -0600, Jeff Epler wrote:
> There are also problems on redhat9, where signals in a fork+exec'd
> subprocess are blocked, for instance. This seemed to be a consequence
> of blocking all signals in thread_pthread.h:PyThread_start_new_thread().
To follow up on my own message, here is a program that demonstrates the
problem I ran into with threads and signals.
doit() uses system() to create a process that should kill itself with a
signal nearly instantly, otherwise it sleeps for one second. If doit()
is called from the main thread or before any threads are created, it
prints a time well under 1 second. If it is run from a thread, it takes
just over a second, because the delivery of the signal in the subprocess
is blocked.
Typical output:
$ python thread-signal-problem.py
not threaded
Elapsed time 0.00420594215393
subthread
Elapsed time 1.00974297523
main thread
Elapsed time 0.00419104099274
import thread, time, os
def doit():
t = time.time()
os.system("kill $$; sleep 1")
t1 = time.time()
print "Elapsed time", t1-t
print "not threaded"
doit()
print "subthread"
thread.start_new(doit, ())
time.sleep(2)
print "main thread"
doit()
More information about the Python-Dev
mailing list