vscode python multithread programming terminate unexpectedly

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)
ref: https://github.com/Microsoft/vscode-python/issues/1191#issuecomment-386443694
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值