【发布时间】:2015-06-08 05:46:59
【问题描述】:
from threading import Thread
class MyClass:
#...
def method2(self):
while True:
try:
hashes = self.target.bssid.replace(':','') + '.pixie'
text = open(hashes).read().splitlines()
except IOError:
time.sleep(5)
continue
# function goes on ...
def method1(self):
new_thread = Thread(target=self.method2())
new_thread.setDaemon(True)
new_thread.start() # Main thread will stop there, wait until method 2
print "Its continues!" # wont show =(
# function goes on ...
这样可以吗? 在 new_thread.start() 之后,主线程一直等到它完成,为什么会这样?我没有在任何地方提供 new_thread.join()。
守护进程没有解决我的问题,因为我的问题是主线程在新线程启动后立即停止,而不是因为主线程执行结束。
【问题讨论】:
标签: python multithreading