wxPython issues

Josiah Carlson jcarlson at nospam.uci.edu
Mon Feb 2 18:38:59 EST 2004


> No, the thing is:
> 
> It is a (still primitive) filemanager, where copy should be run in a
> worker thread
> in background (you can copy 1 GB file), and you should be able to work
> with the
> program without waiting

I see.  Well then, here is a version that doesn't have all the details, 
but it will properly handle working with and shutting down while dealing 
with one working thread.


import Queue
import threading

tocopy = Queue.Queue()
working = threading.Lock()


def workerthread():
     frame = wxGetApp().GetFrame()
     while 1:
         g_nGuiResult = tocopy.get()
         if working.acquire(0):
             #do whatever you were supposed to do
             wxPostEvent(frame, <notification of operation complete>)
         else:
             #we are supposed to shut down
             return

threading.Thread(target=workerthread).start()


     def OnOverwriteDlg(self, event):
         print "OnOverwriteDlg"
         dlg = COverwriteDlg ()
         dlg.m_strInfo = g_strTitle
         g_nGuiResult = dlg.ShowModal()
         print g_nGuiResult
         if a copy were supposed to happen:
             tocopy.put(g_nGuiResult)

     def OnClose(self, event):
         #save startup preferences
         # show a status update stating that we are waiting for the
         # worker thread to finish copying
         wxYield()          #so that the status update is actually shown
         working.acquire()  #get the working lock so that the worker
                            #thread is notified that it should quit
         tocopy.put(None)   #to wake up the worker thread if necessary



More information about the Python-list mailing list