simple thread problem

Duncan Grisby dgrisby at uk.research.att.com
Tue Jun 20 05:42:02 EDT 2000


In article <newscache$2quewf$nzd$1 at jenpc07.jennic.com>,
 Robert Cragie <rcc at nospamthanks_jennic.com> wrote:

>The mysterious message you get is when 'threading' encounters threads
>created in 'thread', so it sounds to me that you are mixing 'threading' and
>'thread' objects - are you using 'threading.Semaphore' or such like? As Aahz
>says, try to do it all using 'threading' objects.
>
>BTW, it's not actually a problem as such - it will probably still work.
>'threading' calls these 'Dummy threads' - look at threading.py for more
>info.

The difficulty is that the threading module keeps a dictionary mapping
thread ids to threading.Thread objects. When it encounters a thread id
which doesn't exist in the dictionary, it creates a DummyThread object
and puts it in the dictionary. The problem is that there is now a
reference to the DummyThread in the dictionary, but no way of getting
rid of it again. If you regularly create and delete threads, these
DummyThread objects accumulate.

This isn't really a problem if you are writing pure Python code, since
you can easily make sure that you create all the threads you need with
the threading module. It _is_ a problem if you need to interface with
some C code which creates its own threads. In that case, you have to
mess with the dictionary in the threading module to remove entries
from it. It would be nice if threading had an API for adding and
removing thread ids from its dictionary.

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