简体   繁体   中英

how to kill a python thread under certain conditions

I am trying to start a thread using python threading module. I want to kill this newly created thread under certain conditions. I have written below code snippet but this seems to hang and process never returns

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)

You'll want to send SIGKILL or SIGTERM , not SIGSTOP .

SIGSTOP pauses the process (which sounds like what you're seeing).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM