Threads and GUI question

Michael Gilfix mgilfix at eecs.tufts.edu
Mon Oct 28 15:45:13 EST 2002


  Since nobody suggested it, I think what you're looking for is the
wxYield () function.  Yes it's true that you can accomplish something
similar with sleep but wxYield is more precise. Essentially, do this:

  done = False
  while not done:
    # Do some stuff
    wxYield ()

  that will relinquish time from the thread to other threads. In
V2.3.3.1, the wxYield function is now part of the wxApp class. If you
don't care about backwards compat, use go ahead and use the instance
version. Keep in mind that wxYield is only a means to an end and you
will have to sleep at some point, so your process doesn't eat all the
CPU time from other processes.

  As for using threads, well, that's mostly a design choice. Yes, you
can accomplish the same thing using asynchronous IO. Some people will
tell you that threads are bad. It really just all depends. A well
designed threaded app can great simplify things. I think it's more
of a personal choice. In this particular case, using select might be
simpler.

                         -- Mike

On Mon, Oct 21 @ 22:23, Pekka Niiranen wrote:
> Hi,
> 
> I am using wxWindows in win2000 to start a loop that writes to a COM -port:
> 
> runOK = 1
> while runOK != -1:
>         -- write data to COM -port--
> 
> My original idea was to have a Stop -selection in menubar,
> that would set runOK = -1 and cause the while loop above to stop.
> 
> The problem is that menubar does not response while
> the while -loop is running.
> 
> Should I use threads or am I missing some simple trick ?
> If using threads, how many do I need ? Only two ?
> 
> -pekka-
>   
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html




More information about the Python-list mailing list