vscode python multithread programming terminate unexpectedly
阿新 • • 發佈:2018-11-22
problem
import threading
import time
def T1_job():
print("T1 start\n")
for _ in range(10):
time.sleep(0.1)
print("T1 finish\n")
def T2_job():
print("T2 start\n")
print("T2 finish\n")
thread_1 = threading.Thread(target=T1_job, name='T1')
thread_2 = threading.Thread(target=T2_job, name='T2' )
thread_1.start() # 開啟T1
thread_2.start() # 開啟T2
# thread_2.join()
# thread_1.join()
print("all done\n")
Terminate unexpectedly(thread_1
dont finish)
T1 start
T2 start
all done
T2 finish
Terminated
solution:
replace default debugger with pythonExperimental
in launch.json
{
"name" : "Python: pythonExperimental",
// https://github.com/Microsoft/vscode-python/issues/1191#issuecomment-386443694
// "type": "python",
"type": "pythonExperimental",
"gevent": true,
"request": "launch",
"program": "${file}",
}
now output is expected:
T1 start
T2 start
T2 finish
all done
T1 finish
- vscode Version: 1.26.1
- ms-python.python 2018.7.1 (23 July 2018)