-1

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)
Sumit
  • 1,953
  • 6
  • 32
  • 58

1 Answers1

-1

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

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

AKX
  • 152,115
  • 15
  • 115
  • 172
  • Problem is SIGKILL terminates the whole script. my last code line is never executed. I only want to kill this particular thread which is calling function – Sumit Mar 25 '20 at 09:12
  • With os.getpid() he is getting the PID of the actual program that created the thread, he is stopping the program instead of the thread – SteapStepper69 Mar 25 '20 at 09:13