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()
0

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.