Thread.exit: spawn threads to watch shared global memory change;

import thread                                   
exitstat = 0 

def child():
    global exitstat
    exitstat = exitstat + 1
    threadid = thread.get_ident()
    print 'Child #:', threadid, exitstat
    thread.exit()
    print 'never reached'

def parent():
    while 1:
        thread.start_new_thread(child, ())
        if raw_input() == 'q': break

parent()

发表评论

电子邮件地址不会被公开。 必填项已用*标注