wierd threading behavior

Neil Hodgson nyamatongwe+thunder at gmail.com
Fri Oct 14 22:42:19 EDT 2005


Qun Cao:

> import thread
> def main():
>     thread.start_new(test.())
> 
> def test():
>     print 'hello'
> 
> main()
> "
> this program doesn't print out 'hello' as it is supposed to do.
> while if I change main()

    The program has exited before the thread has managed to run. It is 
undefined behaviour whether secondary threads survive main thread 
termination but it looks like they don't on your system.

    Use the threading module and call join to wait for all threads to 
complete before exiting the program.

    Neil



More information about the Python-list mailing list