wierdness with pythonwin dialogs, threads & refcounts

Dave Kirby dave_kirby at eur.3com.com
Mon Jun 21 17:51:12 CEST 1999


On Thu, 17 Jun 1999 19:15:42 -0500, "Gordon McMillan" >
>I played with this enough to find that he's onto something. Without
>any threading, the dialog gets a WM_DESTROY and goes thru __del__.
>When executed from a threading.Thread, it never goes thru OnDestroy.
>I tried doing DoModal myself, then un-hooking the messages myself.
>No luck. Perhaps because there's no parent window, and the trhead
>does not have a Windows message queue?

Yep, I have got it to work correctly by replacing the
thread.start_new_thread function with my own version using the
WinThread class:

#------- 8< -----------------------------
from pywin.mfc.thread import WinThread

class MyThread(WinThread):
  def __init__(self, fn, args ):
    WinThread.__init__(self)
    self.fn = fn
    self.args = args
    
  def InitInstance(self):
    apply( self.fn, self.args )    
    self.PumpIdle()
    self.close()

def start_win_thread( fn, args ):
    thread = MyThread( fn, args )
    thread.CreateThread()
#------- 8< -----------------------------

I am still climbing the learning cliff of Win32 threads so I dont know
if it is the approved way of doing it, but it seems to work well
enough for my purposes.

	Dave K





More information about the Python-list mailing list