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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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.