Python多线程之线程创建和终止(二)

2015-02-02 14:37:55 · 作者: · 浏览: 29
g.currentThread())+'stoped\n'?
? ? print 'after A stoped, '+FileA.name + ' closed? '+repr(FileA.closed)+'\n'?
? ? if not FileA.closed:?
? ? ? ? print 'You see the differents, the resource in subthread may not released with setDaemon()'?
? ? ? ? FileA.close()?
if __name__ =='__main__':?
? ? print '-------stop subthread example with Event:----------\n'?
? ? evtstop()?
? ? print '-------Daemon stop subthread example :----------\n'?
? ? daemonstop()?


运行结果是:


-------stop subthread example with Event:----------?
<_MainThread(MainThread, started 2436)>alive?
testA.txt closed? False?
testB.txt closed? False?
subthreadA alive?
subthreadB alive?
?
<_MainThread(MainThread, started 2436)>send stop signal?

close opened file in subthreadA?
close opened file in subthreadB?
?
subthreadA stoped?
subthreadB stoped?
?
<_MainThread(MainThread, started 2436)>stoped?
after A stoped, testA.txt closed? True?
after A stoped, testB.txt closed? True?
-------Daemon stop subthread example :----------?
<_MainThread(MainThread, started 2436)>alive?
testA.txt closed? False?
subthreadA alive?
subthreadA stoped?
<_MainThread(MainThread, started 2436)>stoped?
after A stoped, testA.txt closed? False?
You see the differents, the resource in subthread may not released with setDaemon()?