我在 python 中运行 2 个线程并执行函数 Do()。
import sys, threading
def do():
print ("Execute")
def run():
def start_thread():
thread = threading.Thread(target = do)
thread.start()
thread.join()
return thread
t1 = start_thread()
t2 = start_thread()
run()
print('Press enter to Quit')
sys.stdin.readline()
运行 run() 函数后,线程 t1 和 t2 超出范围。但是,根据 VS-Code,它们仍处于 Running 模式。
我等待他们join()。这意味着它们被终止了。那么,他们怎么还在跑?如何安全地释放那些线程?
请您参考如下方法:
- 进入 launch.json(Ctrl+Shift+P 并输入文件名)
- 将启动选项的设置从
"type":"python"更改为"type":"pythonExperimental"
好像是vscode的bug。该解决方案是针对 issue that you reported. 发布的
