[Python-Dev] Python threads end up blocking signals in subprocesses

Jeff Epler jepler at unpythonic.net
Thu Dec 18 20:23:55 EST 2003


On Thu, Dec 18, 2003 at 10:22:34PM +0100, Martin v. Löwis wrote:
> Can you find out what $$ is, and what the PIDs and thread IDs of all
> participating threads are?

I'm not sure what all information I should try to gather for you.  Let me
know if you think this is enough to file a bug report with...  I changed
the example to make it clearer that it's the subprocess ignoring the
signal that is the problem, not anything in Python that is taking time
to notice the death of a child process.

Typical output (of course, pids and ppids change from run to run.  I
didn't find gettid(), I think thread.get_ident() is not what you were
asking for):
	not threaded
	os.getpid() -> 6444
	os.getppid() -> 6332
	thread.get_ident() -> 1074152064
	shell process 6445
	thread ppid 6444
	Elapsed time 0.00640296936035

	subthread
	os.getpid() -> 6444
	os.getppid() -> 6332
	thread.get_ident() -> 1082547504
	shell process 6447
	thread ppid 6444
	kill failed
	Elapsed time 1.01621508598

	main thread
	os.getpid() -> 6444
	os.getppid() -> 6332
	thread.get_ident() -> 1074152064
	shell process 6449
	thread ppid 6444
	Elapsed time 0.00641894340515


:r threadbug.py
import thread, time, os

def doit():
	print "os.getpid() ->", os.getpid()
	print "os.getppid() ->", os.getppid()
	print "thread.get_ident() ->", thread.get_ident()
        t = time.time()
        os.system("echo shell process $$; echo thread ppid $PPID; kill $$; echo kill failed; sleep 1")
        t1 = time.time()
        print "Elapsed time", t1-t
	print

print
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