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

Thomas Jollans tjol at tjol.eu
Mon Oct 23 17:26:00 EDT 2017


On 23/10/17 18:34, Josh Jacobson wrote:
> The two functions in the subject are not fully implementable on Windows,
> and so I am looking for an alternative.
> 
> Relevant SO postings including full code and description, with bounty:
> Freezes
> <https://stackoverflow.com/questions/46797770/tkinter-application-freezes-while-continually-polling-pipe-for-contents-multi>,
> Input
> <https://stackoverflow.com/questions/46778491/how-can-i-implement-an-input-method-in-a-tkinter-parent-script-with-the-displ>
> 
> ----
> 
> I have two scripts:
> 
> *Processor_child.py*: Its purpose is to perform a number of data analysis
> and cleaning operations. This must perform the same operations when run
> alone (without Tkinter_parent.py) as it does when packaged into a GUI with
> Tkinter_parent.py.
> 
> *Tkinter_parent.py*: Its purpose is to provide a GUI for those who can't
> use Processor_child directly.Within Processor_child, there are for loops
> that ask the user for input on each iteration. These prompts need to appear
> in the Tkinter app, accept the input, and send it back to Processor_child.
> 
> ----
> 
> The main issue is having the script not move forward on execution until
> input has been sent.
> 
> I know of three ways to theoretically solve this, but *none of these work
> in production on a Windows machine*:
> 
> 1. while pipe1.poll() != True:
> 
>         time.sleep(0.1)

My intuition tells me that this kind of thing should be in a separate
thread rather than buried in the main loop. 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.

Not sure if this will help.

> 
> This causes constant loading and a "freezing" like user experience.
> 
> 2. multiprocessing.connection.wait
> 
> From the documentation: ""Windows: ... Note that pipe handles and socket
> handles are not waitable handles."
> 
> 3. Tkinter file handlers
> 
> From the documentation: "This feature is not available on Windows."

Both of these are about Windows not having the same select() system call
as *nix. You can work around this by using a local (loopback) TCP
connection rather than a multiprocessing-supplied pipe (--> socket
module). Then you can use select on both Windows and *nix (-->select
module).

Why do the GUI and the processing have to be in separate scripts? Maybe
it would be easier to import the processing bits as a module and then
run them "directly" - possibly via multiprocessing or threading.

> 
> 
> *Given that none of the 3 available options works on Windows, what options
> are available for Windows machines?*
> 
> See Tkinter application 'freezes' while continually polling Pipe for
> contents (multiprocessing)
> <https://stackoverflow.com/questions/46797770/tkinter-application-freezes-while-continually-polling-pipe-for-contents-multi>
> and How can I implement an `input` method in a Tkinter parent script, with
> the displayed prompt and return value being sent back to a child script?
> <https://stackoverflow.com/questions/46778491/how-can-i-implement-an-input-method-in-a-tkinter-parent-script-with-the-displ>
> for further description and code samples.
> 




More information about the Python-list mailing list