no current thread warning
Duncan Grisby
dgrisby at uk.research.att.com
Sat Dec 16 09:12:13 EST 2000
In article <91dtv0$g93$1 at panix6.panix.com>, Aahz Maruch <aahz at panix.com> wrote:
[...]
># Dummy thread class to represent threads not started here.
># These aren't garbage collected when they die,
># nor can they be waited for.
This behaviour is a problem for any C / C++ code which creates its own
threads, then calls into Python. It would be nice if threading.py
contained a proper API for creating and deleting threading.Thread
objects for threads created outside of Python.
In omniORBpy, I have exactly this problem. The work-around is to
create my own threading.Thread objects, and manually manipulate the
threading._active dictionary. That's ugly because it depends on the
threading module's internal structure. The Python code to do it is
below. The C++ side caches the Thread objects so they don't have to be
created on each up-call from C++ to Python.
# WorkerThread class used to make the threading module happy during
# operation dispatch.
# *** Depends on threading module internals ***
class WorkerThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self, name="omniORB")
self._Thread__started = 1
self.id = threading._get_ident()
threading._active_limbo_lock.acquire()
if threading._active.has_key(self.id):
self.add = 0
else:
self.add = 1
threading._active[self.id] = self
threading._active_limbo_lock.release()
def delete(self):
if self.add:
threading._active_limbo_lock.acquire()
del threading._active[self.id]
threading._active_limbo_lock.release()
def _set_daemon(self): return 1
Cheers,
Duncan.
--
-- Duncan Grisby \ Research Engineer --
-- AT&T Laboratories Cambridge --
-- http://www.uk.research.att.com/~dpg1 --
More information about the Python-list
mailing list