Apr-27-2025, 04:19 PM
Apr-27-2025, 05:10 PM
(Apr-27-2025, 04:19 PM)Azdaghost Wrote: [ -> ]how do I delete a threadwe don't delete threads
Apr-27-2025, 07:25 PM
It's possible, but it is not exposed. It's not exposed, because it locks up the interpreter.
Here is a way to end a thread. The Event object is used, to communicate thread safe:
Here is a way to end a thread. The Event object is used, to communicate thread safe:
import time from threading import Event, Thread, Timer def worker(event): while not event.is_set(): print("Ping") time.sleep(1) def main(): event = Event() worker_thread = Thread(target=worker, args=(event,)) worker_thread.start() # set event after 5 seconds Timer(5, event.set).start() # timer calls event.set() after 5 seconds if __name__ == "__main__": main()
Apr-28-2025, 08:08 AM
OP asks how to delete thread here on the python forum
Apr-28-2025, 07:30 PM
(Apr-28-2025, 08:08 AM)buran Wrote: [ -> ]OP asks how to delete thread here on the python forum
So you can't delete threads at python-forum.io and threading.Thread doesn't allow you to delete/terminate threads either.
I've been here for a while and realized that I've never needed this function.