Jesh Kundem Jesh Kundem - 1 year ago 261
Python Question

Python - Cannot join thread - No multiprocessing

I have this piece of code in my program. Where OnDone function is an event in a wxPython GUI. When I click the button DONE, the OnDone event fires up, which then does some functionality and starts the thread self.tstart - with target function StartEnable. This thread I want to join back using self.tStart.join(). However I am getting an error as follows:

Exception in thread StartEnablingThread:
Traceback (most recent call last):
File "C:\Python27\lib\", line 801, in __bootstrap_inner
File "C:\Python27\lib\", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "//$/kundemj/windows/my documents/Production GUI/Trial python Codes/", line 638, in StartEnable
File "C:\Python27\lib\", line 931, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread

I have not got this type of error before. Could any one of you guys tell me what I am missing here.

def OnDone(self, event):
self.tStart = threading.Thread(target=self.StartEnable, name = "StartEnablingThread", args=())

def StartEnable(self):
while True:
if int(self.pressure_text_control.GetValue()) < 50:
print "HELLO"
print "hello2"

I want to join the thread after the "if" condition has executed. Until them I want the thread to run.

Answer Source

When the StartEnable method is executing, it is running on the StartEnablingThread you created in the __init__ method. You cannot join the current thread. This is clearly stated in the documentation for the join call.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download