mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
stdpy: fix direct.stdpy.threading cleanup issue after thread runs
Fixes: #164
This commit is contained in:
parent
2d1f0e4866
commit
1dc02f6a28
@ -102,7 +102,14 @@ class Thread(ThreadBase):
|
|||||||
self.__dict__['daemon'] = current.daemon
|
self.__dict__['daemon'] = current.daemon
|
||||||
self.__dict__['name'] = name
|
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))
|
threadId = _thread._add_thread(self.__thread, weakref.proxy(self))
|
||||||
self.__dict__['ident'] = threadId
|
self.__dict__['ident'] = threadId
|
||||||
|
|
||||||
@ -113,12 +120,12 @@ class Thread(ThreadBase):
|
|||||||
_thread._remove_thread_id(self.ident)
|
_thread._remove_thread_id(self.ident)
|
||||||
|
|
||||||
def is_alive(self):
|
def is_alive(self):
|
||||||
return self.__thread.isStarted()
|
return self.__thread is not None and self.__thread.is_started()
|
||||||
|
|
||||||
isAlive = is_alive
|
isAlive = is_alive
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self.__thread.isStarted():
|
if self.__thread is None or self.__thread.is_started():
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
if not self.__thread.start(core.TPNormal, True):
|
if not self.__thread.start(core.TPNormal, True):
|
||||||
@ -393,7 +400,7 @@ def enumerate():
|
|||||||
_thread._threadsLock.acquire()
|
_thread._threadsLock.acquire()
|
||||||
try:
|
try:
|
||||||
for thread, locals, wrapper in list(_thread._threads.values()):
|
for thread, locals, wrapper in list(_thread._threads.values()):
|
||||||
if wrapper and thread.isStarted():
|
if wrapper and wrapper.is_alive():
|
||||||
tlist.append(wrapper)
|
tlist.append(wrapper)
|
||||||
return tlist
|
return tlist
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user