Windows alternative: multiprocessing.connection.wait on Pipe, Tkinter File Handlers

Stephan Houben stephanh42 at gmail.com.invalid
Thu Oct 26 10:24:13 EDT 2017


Op 2017-10-23, Thomas Jollans schreef <tjol at tjol.eu>:
> You might wait in a thread
> and somehow (no idea what the best way to do this is in tkinter) pass a
> message to the GUI thread when it's done.

AFAIK, this is a real problem in Tkinter on Windows.
On Posix you can use the self-pipe trick.
But on Windows, Tkinter cannot wait on a pipe.

I see two solutions (well, three, really):

1. Use a different toolkit, e.g. PyQt has explicit support for notifying
   the GUI thread from another thread.

2. Use Cygwin-based Python. If this is an option, the Cygwin people did 
   already all the heavy lifting for providing Posix-like select()
   semantics.

3. Regular polling. This has been rejected by the OP, but in my
   experience can produce reasonable results when done "properly",
   i.e. use the Tkinter "after" method with a reasonable time interval
   (in the past I have used a strategy of starting with 10 ms and then,
   on no event, slowly back off to polling every 200ms).

   It is by far the simplest solution, and AFAIK the only one which will
   work with the standard Python distribution + Tkinter.

Stephan



More information about the Python-list mailing list