0

Is it possible a intterrupt a python threading, example i want interrupt that thread 30 seconds later.

import threading
import time

def waiting():
    print("thread is started")
    time.sleep(60)
    print("thread is finished")

thread = threading.Thread(target=waiting, name="thread_1")
thread.start()
omer
  • 1

1 Answers1

-1

I find the solution, i am using multiprocessing module, the solution example:

from multiprocessing import Process
import time

def waiting():
    print("thread is started")
    time.sleep(60)
    print("thread is finished")


if __name__ == '__main__':
    p = Process(target=waiting)
    p.start()
    time.sleep(30)
    p.terminate()

Process is started and terminate 30 seconds later.

omer
  • 1