[issue874900] threading module can deadlock after fork

Jesse Noller report at bugs.python.org
Thu Jul 17 19:35:04 CEST 2008


Jesse Noller <jnoller at gmail.com> added the comment:

To add to ben's comment, under py3k the third test hangs, if you pull 
out the basic script code being executed in subprocess:

if 1:
        import sys, os, time, threading

        # a thread, which waits for the main program to terminate
        def joiningfunc(mainthread):
            mainthread.join()
            print('end of thread')
    
if 1:
    main_thread = threading.current_thread()
    def worker():
        childpid = os.fork()
        if childpid != 0:
            os.waitpid(childpid, 0)
            sys.exit(0)

        t = threading.Thread(target=joiningfunc,
                             args=(main_thread,))
        print('starting worker')
        t.start()
        print('joining worker')
        t.join() # Should not block: main_thread is already stopped

    w = threading.Thread(target=worker)
    w.start()

You'll note it hangs promptly at the join()

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue874900>
_______________________________________


More information about the Python-bugs-list mailing list