psy*_*tic 6 python multithreading
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 ...
Run Code Online (Sandbox Code Playgroud)
有可能这样做吗?在new_thread.start()主线程等待它完成之后,为什么会发生这种情况?我没有在任何地方提供new_thread.join().
守护进程没有解决我的问题,因为我的问题是主线程在新线程启动后立即停止,而不是因为主线程执行结束.