[PySide] Keeping GUI responsive

Sivan Greenberg sivan at omniqueue.com
Sun Dec 8 16:54:10 CET 2019


Hi Israel,

 If your non main function is mostly IO bound, you could try implement your
processing function with an interface that allows for polling of results
using co-routines which is very slim and very robust (I used that in the
past for several PyQt & PySide small apps but also for a full blown project
for Ubuntu back in 2006[0] , though with PyGTK - but principle is same) and
will allow your GUI main loop to be in charge, even if you ever need to use
a spawned shell command or program! (see links below)

 It seems that nowadays, there are even ready made libs for that (this one
seems very interesting): https://github.com/reclosedev/async_gui and also
supports abstraction over multiprocessing which would support you even if
the the subtask is indeed CPU intensive (like data cleansing , validation
etc).

 If you're using python 3 , the whole coroutines interface has been greatly
simplified, and could be easier to use, however the first guide will
explain in deep and show how to achieve cooperative multitasking using
plain Python 2.x interface:
-
http://masnun.com/2015/11/13/python-generators-coroutines-native-coroutines-and-async-await.html
-
https://medium.com/velotio-perspectives/an-introduction-to-asynchronous-programming-in-python-af0189a88bbb

HTH,

-Sivan

[0]:
http://www.ubuntugeek.com/hubackup-backup-application-for-ubuntu-home-users.html

On Thu, Dec 5, 2019 at 1:41 AM Israel Brewster <ijbrewster at alaska.edu>
wrote:

> I know this is a FAQ, however I haven’t been able to make any of the
> standard answers work for me. Here’s the situation:
>
> - using PySide2 5.12.2
> - I have an object (QMainWindow subclass) that contains most of the code
> for my application
> - One of the functions that runs in response to user input takes around 2
> seconds to run. The GUI obviously freezes during this time (BAD!)
> - Said function needs to access and modify several large variables (pandas
> data frames) from the main object
>
> So here’s the problem: If I run this function as a separate (python)
> thread, that doesn’t help - the GUI is still frozen. I’m thinking this is
> due to the GIL, but I could be wrong about that. Running under the
> multiprocessing module, however, doesn’t appear to be an option due to the
> number and size of the data structures that the function needs to modify,
> and if I try just to see what happens, the process actually crashes.
>
> So what are my options here? How can I keep the GUI responsive while this
> function runs, without being able to spin it off as a separate process? Or
> is the only option going to be to completely rip apart the function and try
> to re-build it in such a way that it can, somehow, still access the memory
> from the main thread, while doing the processing in a separate function?
> ---
> Israel Brewster
> Software Engineer
> Alaska Volcano Observatory
> Geophysical Institute - UAF
> 2156 Koyukuk Drive
> Fairbanks AK 99775-7320
> Work: 907-474-5172
> cell:  907-328-9145
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> https://lists.qt-project.org/listinfo/pyside
>


-- 
-Sivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20191208/fc69df57/attachment.html>


More information about the PySide mailing list