Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82344

Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor

Path csiph.com!usenet.pasdenom.info!aioe.org!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <torriem+gmail@torriefamily.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.017
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; '(using': 0.07; 'callback': 0.09; 'executes': 0.09; 'subject:using': 0.09; 'wrapped': 0.09; 'python': 0.11; 'gui': 0.12; 'thread': 0.14; 'blocking': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'subject:PyQt': 0.16; 'subject:user': 0.16; 'subject:when': 0.16; 'threads,': 0.16; 'threads.': 0.16; 'wrote:': 0.18; 'mechanism': 0.19; 'header:User-Agent:1': 0.23; 'frameworks': 0.24; "shouldn't": 0.24; 'regardless': 0.24; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; "doesn't": 0.30; "i'm": 0.30; 'code': 0.31; 'talked': 0.31; 'skip:c 30': 0.32; 'weeks': 0.32; 'interface': 0.32; 'another': 0.32; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'done,': 0.36; 'doing': 0.36; 'should': 0.36; 'list': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'explain': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'catch': 0.60; 'signal': 0.60; 'most': 0.60; 'course': 0.61; 'finish': 0.65; 'here': 0.66; 'asynchronous': 0.84; 'calls,': 0.84; 'examples.': 0.84; 'sitting': 0.91; 'urls,': 0.91
X-Virus-Scanned amavisd-new at torriefamily.org
Date Wed, 10 Dec 2014 22:25:15 -0700
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11
MIME-Version 1.0
To python-list@python.org
Subject Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor
References <c9113f8e-ab16-4226-bd68-28c56a88aeda@googlegroups.com>
In-Reply-To <c9113f8e-ab16-4226-bd68-28c56a88aeda@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16842.1418275530.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418275530 news.xs4all.nl 2947 [2001:888:2000:d::a6]:35623
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82344

Show key headers only | View raw


On 12/10/2014 09:52 PM, iMath wrote:
> I think the user interface shouldn't be freezed when using
> concurrent.futures.ThreadPoolExecutor here,as it executes
> asynchronously , 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

In most any GUI framework, regardless of your use of threads, your
callbacks must return control to the main loop immediately (whether an
on-click or an on-timer event), or the GUI *will* freeze.

You are spawning threads to download the urls, then sitting there
waiting for them to finish in the callback.  Of course the GUI will
freeze; your callback is blocking it.  What you should be doing is
spawning the threads to do the download, then have the threads (using a
proper QThread mechanism or some other semaphore mechanism) raise a
signal to indicate they are done, which you will then catch in the main
loop as a normal callback.  And really when it comes to I/O and GUIs,
asynchronous calls are always better than threads.  Not sure what Qt has
in the way of asynchronous i/o calls, and I'm not familiar enough with
the various async i/o frameworks in Python to speak to that, though I
did use Python-Twisted once... very powerful once you get your head
wrapped around it.

Look through the list archives because in the last 3 or 4 weeks I and
another Python user talked proper thread use with PyQt or PySide, with
code examples.

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor iMath <redstone-cold@163.com> - 2014-12-10 20:52 -0800
  Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor Michael Torrie <torriem@gmail.com> - 2014-12-10 22:25 -0700
    Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor iMath <redstone-cold@163.com> - 2014-12-11 19:20 -0800
      Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor Michael Torrie <torriem@gmail.com> - 2014-12-11 23:07 -0700
        Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor Marko Rauhamaa <marko@pacujo.net> - 2014-12-12 09:18 +0200
          Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor Chris Angelico <rosuav@gmail.com> - 2014-12-12 18:42 +1100
            Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor Marko Rauhamaa <marko@pacujo.net> - 2014-12-12 10:43 +0200
  Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor Mark Summerfield <list@qtrac.plus.com> - 2014-12-18 03:16 -0800
    Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor Michael Torrie <torriem@gmail.com> - 2014-12-18 09:29 -0700

csiph-web