wierd threading behavior

Qun Cao quncao at gmail.com
Fri Oct 14 19:00:15 EDT 2005


Hello,

I am just starting to play threading in python, here is a really
interesting problem I am very curious about:
"
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() into :
"
def main():
    while 1:
        thread.start_new(test.())
"
It goes on to print 'hello' forever.

while if I use:
"
def main():
    for i in range(5):
        print i
        thread.start_new(test.())
"
It prints out 1,2,3,4,5 in main(), but still doesn't print out anything
from test()!

This is really wierd behavior for me, I am sure it's just something
simple&stupid, please enlighten me! 

Thanks, 
qun




More information about the Python-list mailing list