Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:28:45+00:00 2026-05-24T10:28:45+00:00

I have a threaded program in Python that works fine except that __del__ does

  • 0

I have a threaded program in Python that works fine except that __del__ does not get called once the thread is running:

class tt(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.stop_event = threading.Event()

    def __del__(self):
        print "Deleting"
        self.stop_event.set()
        time.sleep(5)

    def run(self):
        self.stop_event.clear()
        while not self.stop_event.isSet():
             self.do_stuff()
        threading.Thread.__init__(self)

    def stop(self):
        self.stop_event.set()

For example if I do

tc = aa()
del tc 

It works fine (I get the deleting message pause etc). However if I do:

tc = aa()
tc.start()
del tc

Then the __del__ does not get run (Note it does execute __del__ when I do tc.start(); tc.stop(); del tc.

I’m running this in ipython

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:28:47+00:00Added an answer on May 24, 2026 at 10:28 am

    The __del__() method is executed when an instance is garbage collected, not when you call del on a name that happens to point to the instance. The latter will only delete the name (which might in some cases result in the instance pointed to by the name being gc’ed).

    A threading.Thread instance will never be garbage collected while the thread is still running, since the instance is still in use in this case. And ditching a name that happens to point to the instance certainly won’t stop the thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on integrating a single-threaded API that does not have any multi-threaded support
If I have a multi-threaded program that reads a cache-type memory by reference. Can
Suppose I have a function in a single threaded program that looks like this
When I run a single-threaded program that i have written on my quad core
I have a C# program that executes a thread. Inside this thread, I have
I have a threaded console application that is working fine, but it's architecture needs
I have a Python program that spawns many threads, runs 4 at a time,
I have a multi threaded program in C that was working well but was
I have a multi-threaded C++ program that deadlocks in some rare cases. The problem
I have a multi-threaded program, where I have one thread to watch over several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.