Is there a way to see why a thread is still open?

J

JohnnyFive

I've got a rather complex program that, for some reason, is not
closing the completed threads when they are finished.

Just to cover my bases, when using the following:

temp = threading.Thread(target=self.processMessages,
args=(msg, args), name="pubmsg subthread")
temp.setDaemon(1)
temp.start()

What I understand is that when 'temp' is done processing, (and there's
no timers or anything, it just processes a message and goes through a
few routines afterwards, but nothing that is a loop/while/or anything
like that), then 'temp' should close on it's own.

So I obviously have something in my code that is keeping the thread
open, but I can't figure out what.

Is there a way to figure out why a thread is staying open? A utility,
or coding trick that I don't know about?

Thanks!
 
D

Dennis Lee Bieber

temp = threading.Thread(target=self.processMessages,
args=(msg, args), name="pubmsg subthread")
temp.setDaemon(1)
temp.start()

What I understand is that when 'temp' is done processing, (and there's
no timers or anything, it just processes a message and goes through a
few routines afterwards, but nothing that is a loop/while/or anything
like that), then 'temp' should close on it's own.
No... .setDaemon() says that when the MAIN thread ends, the daemon
thread, even if still processing, will die (whereas a non-daemon thread
can block the main thread from exiting).
So I obviously have something in my code that is keeping the thread
open, but I can't figure out what.
Yeah... Off-hand, the reference in "temp" may be holding the thread
object -- on the assumption that you might need to access attributes
that are inside of it once it completed {this is hypothesis, I've not
tried}...

Performing, somewhere in the main thread

temp.join()
del temp

should get rid of it...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top