usage of functools.partial in in parallelism

Sivan Greenberg sivan at vitakka.co
Sun Jul 31 08:46:24 EDT 2016


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" <stefan_ml at behnel.de> 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
>



More information about the Python-list mailing list