no current thread warning

Duncan Grisby dgrisby at
Sat Dec 16 15:12:13 CET 2000

In article <91dtv0$g93$1 at>, Aahz Maruch <aahz at> 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
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 = threading._get_ident()
        if threading._active.has_key(
            self.add = 0
            self.add = 1
            threading._active[] = self

    def delete(self):
        if self.add:
            del threading._active[]

    def _set_daemon(self): return 1



 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- --

More information about the Python-list mailing list