Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Sivan Greenberg Newsgroups: comp.lang.python Subject: Re: usage of functools.partial in in parallelism Date: Sun, 31 Jul 2016 15:46:24 +0300 Lines: 51 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de s5ycUWYzpRMJ8KPm4eBUDQfyIgKCSx1GbCdTNtPOrO8g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'used.': 0.05; '(of': 0.07; 'caller': 0.07; 'cc:addr:python-list': 0.09; 'invocation': 0.09; 'question?': 0.09; 'subject:skip:f 10': 0.09; 'python': 0.10; '"i': 0.16; '*this*': 0.16; '2016': 0.16; 'cc:name:python list': 0.16; 'it".': 0.16; 'maintainer': 0.16; 'readable': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'spotted': 0.16; 'subject:usage': 0.16; 'verbose': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'case.': 0.18; 'comparing': 0.18; 'differ': 0.18; 'stefan': 0.18; '>': 0.18; 'thanks.': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(the': 0.22; 'saying': 0.22; 'arguments': 0.22; 'pass': 0.22; 'code.': 0.23; 'bit': 0.23; '(or': 0.23; 'header:In-Reply-To:1': 0.24; 'wondering': 0.25; "doesn't": 0.26; 'example': 0.26; 'points': 0.27; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'about.': 0.29; 'oop': 0.29; 'ups': 0.29; 'wraps': 0.29; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.30; 'class.': 0.30; 'e.g.': 0.30; 'guess': 0.31; 'entry': 0.31; "can't": 0.32; 'maybe': 0.33; 'class': 0.33; 'url:python': 0.33; 'url:listinfo': 0.34; 'running': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'next': 0.35; 'solving': 0.35; 'tasks': 0.35; 'widely': 0.35; 'asking': 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'url:org': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'method': 0.37; 'data': 0.39; 'sure': 0.39; 'does': 0.39; 'url:mail': 0.40; 'some': 0.40; 'care': 0.60; 'your': 0.60; 'skip:u 10': 0.61; 'per': 0.62; 'details': 0.62; 'more': 0.63; 'different': 0.63; 'within': 0.64; 'binding': 0.66; 'here': 0.66; 'forward': 0.66; 'god': 0.67; 'jul': 0.72; 'special': 0.73; 'quicker': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vitakka-co.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=YOJ5AsUGeEgi51kSBd9uzIQB8CyTJKmgqxMkoyYAtwo=; b=kwqhdqk06rid+NmfP4U2NTSUgbt+t68DZNgNJG7WcyJteE1fLIsDRYUoDyHce8frvi vqgfxhk+UNiAd4urrnqzTYZS7VopMIucW0z+Hn7dKeX7t+UvOoQxd4ehworxtvLJMMPg Wj2iExDDi9YlUFaDfwTU2Xcvmf+pdtCNR0G2/k8E021KfbGO/O7YFT+s9uzfqYaWSexj zVGk9m5yVN8pjuDznr7eTjC4vjCt2d9X7PeqOuNA9iQCzMGjWmJyQCKhCRrvOseTMAbI I9SM0Ton6bA39VR1mgRVFo/j6omSnFdpKIpA9ctJvv9MSJzP0p/vTqPWZ++XOhkrZmGC /Ayg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=YOJ5AsUGeEgi51kSBd9uzIQB8CyTJKmgqxMkoyYAtwo=; b=fHrEt5rXVgo6k1WxIm8JE/Qw97xrBS+2UAEj7buIGwGHE9RbcxHVQnLQDH7IcAKI6x uaQ0xEJfRbqoVlk/T+rT3Vw7GIH3CXNAcLOdtmuZGYx0CBMQZhzpUOoLe+Rd0/NKANkQ 1tOEK3Y71HMpllPk8OAjwuS5kbuzhs4eotMKVj2lrA3TbzqiZooiJZyV0K2m2pOeAl2M fWJHMbMsop/HyWH0S1JAuMNsaiDIBjw9lswat2jVrUYcn0JxlPgSs0SjnA5gSU2ukH1d lWfqojt8VHfhJ1JexadxC2bvgZIPwK/uStnMT+ru7Vf594FIQ/FfklosqKNR3cZ7q8I3 uQ1A== X-Gm-Message-State: AEkoouu7h0BDa9GttNdvY2W2GqikTgBh1cUyfi2gFWCjcy9E+thPzZ4xG9I9kYt2JMgjO7khd2s3Y3DPwMWZLg== X-Received: by 10.55.120.7 with SMTP id t7mr62805097qkc.131.1469969184700; Sun, 31 Jul 2016 05:46:24 -0700 (PDT) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.22 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com comp.lang.python:112135 That's exactly the answer I was looking for. Thanks. I got used too much I guess to solving problems the OOP way, e.g. my code wraps the session.get invocation with a class to pack together the arguments and data and also took care of parallelism using gevent, from within the class. While a bit more verbose (or god forbid..unpythonic?) I find it much nore readable in my taste and easier to pass on to the next code maintainer in the heritage. -Sivan On 31 Jul 2016 11:43, "Stefan Behnel" wrote: > Sivan Greenberg schrieb am 30.07.2016 um 23:15: > > I'm wondering about the use of partial in writing parallel code. Is is > it > > quicker than re-evaluating arguments for a multiple session.get()'s > method > > with different , for example (of requests) ? > > > > Or maybe it is used to make sure the arguments differ per each > invocation > > ? (the parallel invocation is supposedly using tasks / co-routine support > > in Python 3. > > > > I can't publish the code I spotted that in. > > > > What are ups and downs of using them when are they in context? > > I'm having difficulties in understanding what exactly you are asking here > and what you are comparing it with, but partial() is just a way of saying > "I want a single thing that calls *this* function with at least (or > exactly) *these* arguments whenever I call it". It's basically binding a > function and some arguments together into a nice package that the eventual > caller doesn't have to know any special details about. > > There is more than one way to do that, but partial is a quick and straight > forward one that is commonly and widely used. Also for entry points when > running code in parallel or concurrently, but there's really nothing > special about that use case. > > Does that answer your question? > > Stefan > > > -- > https://mail.python.org/mailman/listinfo/python-list >