[PySide] user interface freezed when using concurrent.futures.ThreadPoolExecutor

David Anes david.anes at gmail.com
Thu Dec 11 09:12:27 CET 2014


Hi,

this is not a Pyside/PyQT bug. This is about Python and the
beloved-and-hated GIL (https://wiki.python.org/moin/GlobalInterpreterLock).

By spawning a lot of threads (like ThreadPoolExecutor does) you are
preventing the UI thread to refresh because there can't be more than one
thread at a time running python code.

To circumvent this, you can put some microsleeps like sleep(0.1) here and
there (so you give the thread scheduler to eventually allocate time for the
UI thread), you can build a synchronization strategy for the threads to
call QApplication.processEvents() in the main thread, or use
multiprocessing instead of threading (that complicates things and,
depending of the problem you have, can even slow down you multithreaded
algorithm).

Hope this helps,
David.


2014-12-10 7:07 GMT+01:00 iMath <2281570025 at qq.com>:

> I think the user interface shouldn't be freezed when using
> concurrent.futures.ThreadPoolExecutor here, but it doesn't meet my
> expectations,anyone can explain why ? any other solutions here to not let
> user interface freezed?‍
>
> code is here
>
> http://stackoverflow.com/questions/27393533/user-interface-freezed-when-using-concurrent-futures-threadpoolexecutor
>> <http://stackoverflow.com/questions/27393533/user-interface-freezed-when-using-concurrent-futures-threadpoolexecutor>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
>
>


-- 
David "kraptor" Anes Alcolea
* @kraptor <http://twitter.com/kraptor> @simlaps
<http://twitter.com/simlaps>
* linkedin.com/in/davidanes
* kraptor.com | simlaps.com | 900grados.es
<http://simlaps.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20141211/d0fdaf05/attachment.html>


More information about the PySide mailing list