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

2017-10-26 Thread Stephan Houben
Op 2017-10-23, Thomas Jollans schreef :
> 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
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2017-10-23 Thread Thomas Jollans
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
> ,
> Input
> 
> 
> 
> 
> 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)
> 
> 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?
> 
> for further description and code samples.
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2017-10-23 Thread Josh Jacobson
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
,
Input




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)

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."


*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)

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?

for further description and code samples.
-- 
https://mail.python.org/mailman/listinfo/python-list