mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
stdpy: fix issues with direct.stdpy.threading thread cleanup
Fixes: #164
This commit is contained in:
parent
a925e0bcd9
commit
1f017997f9
@ -227,6 +227,7 @@ def _remove_thread_id(threadId):
|
|||||||
|
|
||||||
_threadsLock.acquire()
|
_threadsLock.acquire()
|
||||||
try:
|
try:
|
||||||
|
if threadId in _threads:
|
||||||
thread, locals, wrapper = _threads[threadId]
|
thread, locals, wrapper = _threads[threadId]
|
||||||
assert thread.getPythonIndex() == threadId
|
assert thread.getPythonIndex() == threadId
|
||||||
del _threads[threadId]
|
del _threads[threadId]
|
||||||
|
@ -108,6 +108,7 @@ class Thread(ThreadBase):
|
|||||||
self.run()
|
self.run()
|
||||||
finally:
|
finally:
|
||||||
self.__thread = None
|
self.__thread = None
|
||||||
|
_thread._remove_thread_id(self.ident)
|
||||||
|
|
||||||
self.__thread = core.PythonThread(call_run, None, name, name)
|
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))
|
||||||
@ -120,15 +121,17 @@ 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 is not None and self.__thread.is_started()
|
thread = self.__thread
|
||||||
|
return thread is not None and thread.is_started()
|
||||||
|
|
||||||
isAlive = is_alive
|
isAlive = is_alive
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self.__thread is None or self.__thread.is_started():
|
thread = self.__thread
|
||||||
|
if thread is None or thread.is_started():
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
if not self.__thread.start(core.TPNormal, True):
|
if not thread.start(core.TPNormal, True):
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -142,8 +145,12 @@ class Thread(ThreadBase):
|
|||||||
def join(self, timeout = None):
|
def join(self, timeout = None):
|
||||||
# We don't support a timed join here, sorry.
|
# We don't support a timed join here, sorry.
|
||||||
assert timeout is None
|
assert timeout is None
|
||||||
self.__thread.join()
|
thread = self.__thread
|
||||||
|
if thread is not None:
|
||||||
|
thread.join()
|
||||||
|
# Clear the circular reference.
|
||||||
self.__thread = None
|
self.__thread = None
|
||||||
|
_thread._remove_thread_id(self.ident)
|
||||||
|
|
||||||
def setName(self, name):
|
def setName(self, name):
|
||||||
self.__dict__['name'] = name
|
self.__dict__['name'] = name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user