Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to delete thread
#1
I keep fixing the script after I ask for help its embarrassing Cry Cry
how do I delete a thread
Reply
#2
(Apr-27-2025, 04:19 PM)Azdaghost Wrote: how do I delete a thread
we don't delete threads
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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:
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()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
OP asks how to delete thread here on the python forum
DeaD_EyE likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Just Practicing Posting. Test Thread. “Sandbox” Thread. No Reply needed, Thanks Doc_AElstein 4 7,823 Dec-21-2017, 08:55 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020