diff --git a/direct/src/stdpy/threading.py b/direct/src/stdpy/threading.py index 1bd0bdd9c8..2a1c875539 100644 --- a/direct/src/stdpy/threading.py +++ b/direct/src/stdpy/threading.py @@ -102,7 +102,14 @@ class Thread(ThreadBase): self.__dict__['daemon'] = current.daemon self.__dict__['name'] = name - self.__thread = core.PythonThread(self.run, None, name, name) + def call_run(): + # As soon as the thread is done, break the circular reference. + try: + self.run() + finally: + self.__thread = None + + self.__thread = core.PythonThread(call_run, None, name, name) threadId = _thread._add_thread(self.__thread, weakref.proxy(self)) self.__dict__['ident'] = threadId @@ -113,12 +120,12 @@ class Thread(ThreadBase): _thread._remove_thread_id(self.ident) def is_alive(self): - return self.__thread.isStarted() + return self.__thread is not None and self.__thread.is_started() isAlive = is_alive def start(self): - if self.__thread.isStarted(): + if self.__thread is None or self.__thread.is_started(): raise RuntimeError if not self.__thread.start(core.TPNormal, True): @@ -393,7 +400,7 @@ def enumerate(): _thread._threadsLock.acquire() try: for thread, locals, wrapper in list(_thread._threads.values()): - if wrapper and thread.isStarted(): + if wrapper and wrapper.is_alive(): tlist.append(wrapper) return tlist finally: