Re: Trying to use threading.local()

2018-09-14 Thread Chris Angelico
On Fri, Sep 14, 2018 at 7:18 PM, Antoon Pardon wrote: > On 14-09-18 10:29, Chris Angelico wrote: >> On Fri, Sep 14, 2018 at 5:25 PM, Antoon Pardon wrote: >>> >>> ... Suppose I have two threads, one in which I need >>> a precision of 3 and the other in which I need a precision of 7. In what >>> ci

Re: Trying to use threading.local()

2018-09-14 Thread Antoon Pardon
On 14-09-18 10:29, Chris Angelico wrote: > On Fri, Sep 14, 2018 at 5:25 PM, Antoon Pardon wrote: >> >> ... Suppose I have two threads, one in which I need >> a precision of 3 and the other in which I need a precision of 7. In what >> circumstances is it needed to use threads-locals to accomplish t

Re: Trying to use threading.local()

2018-09-14 Thread Chris Angelico
On Fri, Sep 14, 2018 at 6:34 PM, Thomas Jollans wrote: > On 14/09/18 10:29, Chris Angelico wrote: >> >> On Fri, Sep 14, 2018 at 5:25 PM, Antoon Pardon >> wrote: >>> >>> On 13-09-18 14:29, Chris Angelico wrote: "Preferred" doesn't exclude the possibility that alternatives are needed

Re: Trying to use threading.local()

2018-09-14 Thread Thomas Jollans
On 14/09/18 10:29, Chris Angelico wrote: On Fri, Sep 14, 2018 at 5:25 PM, Antoon Pardon wrote: On 13-09-18 14:29, Chris Angelico wrote: "Preferred" doesn't exclude the possibility that alternatives are needed, though. For example, good luck making decimal.Decimal contexts work correctly withou

Re: Trying to use threading.local()

2018-09-14 Thread Chris Angelico
On Fri, Sep 14, 2018 at 5:25 PM, Antoon Pardon wrote: > On 13-09-18 14:29, Chris Angelico wrote: >> "Preferred" doesn't exclude the possibility that alternatives are >> needed, though. For example, good luck making decimal.Decimal contexts >> work correctly without the help of thread-locals - ther

Re: Trying to use threading.local()

2018-09-14 Thread Antoon Pardon
On 13-09-18 14:29, Chris Angelico wrote: > "Preferred" doesn't exclude the possibility that alternatives are > needed, though. For example, good luck making decimal.Decimal contexts > work correctly without the help of thread-locals - there MIGHT be a > way to do it, but even if there is, it sure w

Re: Trying to use threading.local()

2018-09-13 Thread Chris Angelico
On Fri, Sep 14, 2018 at 1:07 AM, Peter Otten <__pete...@web.de> wrote: > However, the trouble begins with > > a/b # magically determine context > > which has no way to smuggle in a third argument. The workaround while not > pretty is at least straightforward: > > context.divide(a, b) Exactly. You

Re: Trying to use threading.local()

2018-09-13 Thread Peter Otten
Chris Angelico wrote: > On Thu, Sep 13, 2018 at 10:22 PM, Peter Otten <__pete...@web.de> wrote: >> Antoon Pardon wrote: >> >>> On 12-09-18 22:14, Peter Otten wrote: As I understand it you need one local() instance that is shared by all workers. Every thead will then see thread-specific v

Re: Trying to use threading.local()

2018-09-13 Thread Chris Angelico
On Thu, Sep 13, 2018 at 10:22 PM, Peter Otten <__pete...@web.de> wrote: > Antoon Pardon wrote: > >> On 12-09-18 22:14, Peter Otten wrote: >>> As I understand it you need one local() instance that is shared by all >>> workers. Every thead will then see thread-specific values. >> >> It has always puz

Re: Trying to use threading.local()

2018-09-13 Thread Peter Otten
Antoon Pardon wrote: > On 12-09-18 22:14, Peter Otten wrote: >> As I understand it you need one local() instance that is shared by all >> workers. Every thead will then see thread-specific values. > > It has always puzzled me how this is useful. The times I work with > threads, I just put thread

Re: Trying to use threading.local()

2018-09-13 Thread Cameron Simpson
On 13Sep2018 12:21, Antoon Pardon wrote: On 12-09-18 22:14, Peter Otten wrote: As I understand it you need one local() instance that is shared by all workers. Every thead will then see thread-specific values. It has always puzzled me how this is useful. The times I work with threads, I just p

Re: Trying to use threading.local()

2018-09-13 Thread Antoon Pardon
On 12-09-18 22:14, Peter Otten wrote: > As I understand it you need one local() instance that is shared by all > workers. Every thead will then see thread-specific values. It has always puzzled me how this is useful. The times I work with threads, I just put thread specific values in the local va

Re: Trying to use threading.local()

2018-09-12 Thread Peter Otten
Steven D'Aprano wrote: > I'm originally posted this on the Python-Ideas list, but this is probably > more appropriate. > > > import time > from threading import Thread, local > > def func(): > pass > > def attach(value): # no new local() here > func.__params__.value = value > >

Re: Trying to use threading.local()

2018-09-12 Thread MRAB
On 2018-09-12 17:16, Steven D'Aprano wrote: I'm originally posted this on the Python-Ideas list, but this is probably more appropriate. import time from threading import Thread, local def func(): pass def attach(value): func.__params__ = local() func.__params__.value = value

Trying to use threading.local()

2018-09-12 Thread Steven D'Aprano
I'm originally posted this on the Python-Ideas list, but this is probably more appropriate. import time from threading import Thread, local def func(): pass def attach(value): func.__params__ = local() func.__params__.value = value def worker(i): print("called from thread %s"