基本上,我有一个程序,我想在其中创建一个线程来执行主线程旁边的某些功能。但是在python中好像我创建线程的时候,直到创建线程还没有完成,才执行到主线程。
看下面的例子:
import threading
import time
def testing():
time.sleep(30)
wt = threading.Thread(target=testing, name="test", daemon=True)
print("Starting thread")
wt.start()
wt.join()
print("do other stuff next to above thread")
如果你运行上面的程序,直到测试函数还没有完成,主程序才会打印do other stuff next to above thread
。
不确定我是否遗漏了某些参数或什么,但有人能告诉我如何创建一个线程来让主程序继续执行吗?
答案 0 :(得分:2)
调用 empty namespace prefix is not supported in XPath
会使脚本停止并等待 wt 完成。
如果您想在 wt 运行时运行其他东西,请稍后再调用 wt.join()
。
试试这个代码看看:
wt.join()