long running task 2013

(wxPython 2.8.10, WinXP)

I am working on something that, when you press a button, a bunch of
calculations happen that take some seconds (and depending on how much
data is to be processed, possibly enough seconds for the user to want
to do switch windows while it is doing it). I've noticed that while
the task is running, if I switch to another application's window and
then switch back, the frame of my wxPython application is completely
white until the task completes.

Is this the "Long running tasks" issue that was written about in 2001
and posted to the wxPython wiki?
http://wiki.wxpython.org/LongRunningTasks

Was it always making the GUI white like this?

Is that page still applicable, for 2.8.x, in 2013? I ask since it's
~12 years old.

Thanks,
Che

Is this the “Long running tasks” issue that was written about in 2001

and posted to the wxPython wiki?

http://wiki.wxpython.org/LongRunningTasks

I assume so.

Was it always making the GUI white like this?

It may depend on the OS and wxPython version, but in my experience this is very common on Linux when something locks up wxPython for whatever reason. (I assume it has something to do with not being able to redraw the window.)

Is that page still applicable, for 2.8.x, in 2013? I ask since it’s

~12 years old.

The API usage is rather archaic and may have changed (in addition to some allowed-but-discouraged practices like “from threading import *”). More generally, however, the threading module is sub-optimal because of the Global Interpreter Lock, which means that the GUI is going to be poorly responsive until the process finishes. I personally prefer a combination of the multiprocessing module to run a task, and threading to monitor the child process and raise events as necessary (which is lightweight enough not to screw up the GUI). Naturally the code for this ends up being much more complex, but it’s easy to detach the execution from the display, of course.

-Nat

···

On Mon, Jun 17, 2013 at 2:48 PM, C M cmpython@gmail.com wrote:

Yep, it is. While your task is churning the GUI isn't processing
update events. I've gotten around this in the past using a background
thread; my GUI puts long actions into a Queue, and the background
thread pops them out sequentially and processes them. The items in
the Queue are each responsible for returning data however they need to
do so; generally by sending things back to the main thread using
wx.CallAfter.

You could also spawn a new thread for each long task; in my application
maintaining sequentiallity was important.

I've got a decent implementation of the whole background thread thing
if you'd like me to send you a copy.

···

On Mon, 17 Jun 2013 17:48:44 -0400 C M <cmpython@gmail.com> wrote:

(wxPython 2.8.10, WinXP)

I am working on something that, when you press a button, a bunch of
calculations happen that take some seconds (and depending on how much
data is to be processed, possibly enough seconds for the user to want
to do switch windows while it is doing it). I've noticed that while
the task is running, if I switch to another application's window and
then switch back, the frame of my wxPython application is completely
white until the task completes.

Is this the "Long running tasks" issue that was written about in 2001
and posted to the wxPython wiki?
LongRunningTasks - wxPyWiki

Was it always making the GUI white like this?

Is that page still applicable, for 2.8.x, in 2013? I ask since it's
~12 years old.

Thanks,
Che

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Rob Gaddi, Highland Technology
18 Otis St.
San Francisco, CA 94103
415-551-1700

C M wrote:

I am working on something that, when you press a button, a bunch of
calculations happen that take some seconds (and depending on how much
data is to be processed, possibly enough seconds for the user to want
to do switch windows while it is doing it). I've noticed that while
the task is running, if I switch to another application's window and
then switch back, the frame of my wxPython application is completely
white until the task completes.

Yep. This happens in any language -- it's not specific to Python.
Here's the reason why this happens.

Windows is all event-driven. Everything that happens in your program is
the result of messages sent to your main thread. The event loop in your
main thread pulls those messages and calls the appropriate handlers.
When your window is covered and then exposed, Windows sends a WM_PAINT
message to your application, asking it to please redraw the sections
that were recently exposed. In your case, your main thread is busy, so
the repaint message just sits in your input queue until your main thread
can get back to checking for messages.

Until you get around to it, the area where your window will be usually
retains the pixels that were there before -- the contents of the app
that used to be on top. If that app had an all-white window, that's
what you'd see. However, each window also has a "default background
color", and there are circumstances where Windows will erase your window
back to that color before it sends the WM_PAINT.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Is this the "Long running tasks" issue that was written about in 2001
and posted to the wxPython wiki?
LongRunningTasks - wxPyWiki

Yes

Was it always making the GUI white like this?

Probably-what's happening is the system is sending a paint event to
you frame, but it's tied up in your calculation and can't re-paint the
window till that is done.

Is that page still applicable, for 2.8.x, in 2013? I ask since it's
~12 years old.

Yup--not much has changed--though I don't know if it mentions
multi-process, which might be a better option than threading for you.

Chris

···

On Jun 17, 2013, at 2:49 PM, C M <cmpython@gmail.com> wrote:

Thanks, Nat, Rob, Tim, and Chris. Very clear. Now I just need to
decide whether I should bother to implement the proper fix or just let
it ride--it's really just aesthetic at this point and the end user in
this case probably doesn't care.

···

On Mon, Jun 17, 2013 at 8:32 PM, Chris Barker - NOAA Federal <chris.barker@noaa.gov> wrote:

On Jun 17, 2013, at 2:49 PM, C M <cmpython@gmail.com> wrote:

Is this the "Long running tasks" issue that was written about in 2001
and posted to the wxPython wiki?
LongRunningTasks - wxPyWiki

Yes

Was it always making the GUI white like this?

Probably-what's happening is the system is sending a paint event to
you frame, but it's tied up in your calculation and can't re-paint the
window till that is done.

Is that page still applicable, for 2.8.x, in 2013? I ask since it's
~12 years old.

Yup--not much has changed--though I don't know if it mentions
multi-process, which might be a better option than threading for you.

Chris

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.