wierdness with pythonwin dialogs, threads & refcounts

Dave Kirby dave_kirby at eur.3com.com
Thu Jun 17 05:49:25 EDT 1999

I have found strange behaviour (strange to me at least) when creating
a pythonwin dialog on a separate thread created using the standard
python thread module.  The dialog object is never deleted since the
thread is keeping references to it. 

The following example uses dlgtest.py that comes with the pythonwin

#------------- 8< ----------------------------
Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from dlgtest import TestDialog
>>> import sys, thread
>>> def test():
...   t = TestDialog()
...   print "refs:", sys.getrefcount(t)
...   t = None
>>> test()
Edit text changed!
refs: 2
>>> thread.start_new_thread( test, () )
>>> refs: 6
#------------- 8< ----------------------------

As you can see from the above, creating the dialog in the thread gives
it an extra 4 references compared with the non-threaded invocation. Is
this a bug, or is the thread module incompatible with pythonwin? If so
how would I do the equivalent using pythonwin threads?  I have read
the available docs, but it is still pretty opaque to me.

Any help would be greatly appreciated.

	Dave K

More information about the Python-list mailing list