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


Groups > comp.lang.python > #112132

Re: usage of functools.partial in in parallelism

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Stefan Behnel <stefan_ml@behnel.de>
Newsgroups comp.lang.python
Subject Re: usage of functools.partial in in parallelism
Date Sun, 31 Jul 2016 10:39:28 +0200
Lines 30
Message-ID <mailman.72.1469954383.6033.python-list@python.org> (permalink)
References <CAMB+yF1pKty0nRBL3ujsoshZAsi=nG+E5JBW=HT_mabhbiiekQ@mail.gmail.com> <nnkdg0$iid$1@blaine.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de wgzFeWTWj5YNXDmmhfNcBgWAvf/KnJ2eeY03zUvKWK3A==
Return-Path <python-python-list@m.gmane.org>
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; 'invocation': 0.09; 'question?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:f 10': 0.09; 'python': 0.10; '*this*': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'it".': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'spotted': 0.16; 'subject:usage': 0.16; 'basically': 0.18; 'case.': 0.18; 'comparing': 0.18; 'differ': 0.18; 'stefan': 0.18; '(the': 0.22; 'saying': 0.22; 'arguments': 0.22; 'code.': 0.23; '(or': 0.23; 'header:In-Reply-To:1': 0.24; 'wondering': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'points': 0.27; 'least': 0.27; 'function': 0.28; 'about.': 0.29; 'ups': 0.29; "i'm": 0.30; 'code': 0.30; 'entry': 0.31; "can't": 0.32; 'maybe': 0.33; 'running': 0.34; 'that,': 0.34; 'tasks': 0.35; 'widely': 0.35; 'asking': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'method': 0.37; 'received:org': 0.37; 'sure': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'per': 0.62; 'details': 0.62; 'more': 0.63; 'different': 0.63; 'binding': 0.66; 'here': 0.66; 'forward': 0.66; 'special': 0.73; 'quicker': 0.84
X-Injected-Via-Gmane http://gmane.org/
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To <CAMB+yF1pKty0nRBL3ujsoshZAsi=nG+E5JBW=HT_mabhbiiekQ@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
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>
X-Mailman-Original-Message-ID <nnkdg0$iid$1@blaine.gmane.org>
X-Mailman-Original-References <CAMB+yF1pKty0nRBL3ujsoshZAsi=nG+E5JBW=HT_mabhbiiekQ@mail.gmail.com>
Xref csiph.com comp.lang.python:112132

Show key headers only | View raw


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

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


Thread

Re: usage of functools.partial in in parallelism Stefan Behnel <stefan_ml@behnel.de> - 2016-07-31 10:39 +0200

csiph-web