stdpy: fix direct.stdpy.threading cleanup issue after thread runs

Fixes: #164
This commit is contained in:
rdb 2017-08-27 16:55:26 +02:00
parent 2d1f0e4866
commit 1dc02f6a28

View File

@ -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: