[英]how to kill a python thread under certain conditions
我正在尝试使用 python 线程模块启动一个线程。 我想在某些条件下杀死这个新创建的线程。 我写了下面的代码片段,但这似乎挂起并且进程永远不会返回
from threading import Thread
import time
import os, signal
def sum():
print("ada")
time.sleep(5)
print("ada1")
current = Thread(target=sum)
current.start()
current.join()
cur_pid = os.getpid()
print(cur_pid)
os.kill(cur_pid, signal.SIGSTOP)
print(current)
您需要发送SIGKILL
或SIGTERM
,而不是SIGSTOP
。
SIGSTOP
暂停该过程(听起来像您所看到的)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.