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


Groups > comp.lang.python > #71130

Re: Real-world use of concurrent.futures

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <andrew.l.mclean@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.070
X-Spam-Evidence '*H*': 0.86; '*S*': 0.00; 'back.': 0.09; 'subject:skip:c 10': 0.09; 'def': 0.12; 'from:addr:andrew': 0.16; 'iterable,': 0.16; 'itertools': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'andrew': 0.30; 'something': 0.35; 'received:google.com': 0.35; 'done,': 0.36; 'yield': 0.36; 'done': 0.36; 'next': 0.36; "i'll": 0.36; 'should': 0.36; 'message-id:@gmail.com': 0.38; 'thank': 0.38; 'tasks': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'days': 0.60; 'ian': 0.60; 'first': 0.61; 'tasks.': 0.68; 'think:': 0.84; 'trick,': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=PhSCmv3/NkYoWDDpRPTGKn/dTcH7oyvM9JSRZXG2QXI=; b=WnRbbT5MKnGOGj+BB03JGa3JX4WQK3e1HdZPlL/1ynYGtQZ+P5qWiOeG1A7+d/ASy4 2HiP3/m42i+3M6bp6Cp0HC3WkKe9d8aabCf/21kqAFau/gwN8munGMfgfh94EtGW/dNT +xpHfeoFKQqgE8u+mCLk/SN+SdQF+cJHXu1YVofhFdEViWJWKUmwJG8pnP42y5eCW8jd CVrGPQlJV/XRwdrf3ML73XgTTtNnM/N7eFDtQlRxxr0XWFH/2UbUW3HQHXWVMnNw4Ub9 8rgSm5vbpI4fXqoTJscmpFOkS3RksJ0pVP7crKZOHPCxViYBgXCZ0V5dTCIxwZBehxHi JA0w==
X-Received by 10.180.184.167 with SMTP id ev7mr1947wic.55.1399583926769; Thu, 08 May 2014 14:18:46 -0700 (PDT)
Sender Andrew McLean <andrew.l.mclean@gmail.com>
X-Google-Original-From Andrew McLean <Andrew.L.McLean@gmail.com>
Date Thu, 08 May 2014 22:18:51 +0100
From Andrew McLean <andrew@andros.org.uk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Real-world use of concurrent.futures
References <536BD338.4070004@andros.org.uk> <CALwzid=WJA2o_k7qBkCpWFNmuQW-e0GGkgtGEFe_QPGN5-gX2g@mail.gmail.com>
In-Reply-To <CALwzid=WJA2o_k7qBkCpWFNmuQW-e0GGkgtGEFe_QPGN5-gX2g@mail.gmail.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.9798.1399583933.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1399583933 news.xs4all.nl 2975 [2001:888:2000:d::a6]:44065
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71130

Show key headers only | View raw


On 08/05/2014 21:44, Ian Kelly wrote:
> I don't think it needs to be "messy". Something like this should do
> the trick, I think:
>
> from concurrent.futures import *
> from itertools import islice
>
> def batched_pool_runner(f, iterable, pool, batch_size):
>   it = iter(iterable)
>   # Submit the first batch of tasks.
>   futures = set(pool.submit(f, x) for x in islice(it, batch_size))
>   while futures:
>     done, futures = wait(futures, return_when=FIRST_COMPLETED)
>     # Replenish submitted tasks up to the number that completed.
>     futures.update(pool.submit(f, x) for x in islice(it, len(done)))
>     yield from done
>

Thank you, that's very neat. It's just the sort of thing I was looking
for. Nice use of itertools.islice and "yield from".

I'll try this out in the next few days and report back.

- Andrew

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


Thread

Re: Real-world use of concurrent.futures Andrew McLean <andrew@andros.org.uk> - 2014-05-08 22:18 +0100

csiph-web