[Python-ideas] Re: Stack-scoped variables

2021-08-19 Thread Guido van Rossum
Oh, I like that. It does feel like a property of the variable. (But can you efficiently enumerate all context vars when creating a thread?) I imagine that thread pools add some complication, because you don’t want to inherit these accidentally between tasks run by the same worker. On Thu, Aug

[Python-ideas] Re: Stack-scoped variables

2021-08-19 Thread Paul Prescod
On Thu, Aug 19, 2021 at 8:43 AM Guido van Rossum wrote: > Perhaps we need a library for creating/managing threads that inherits all > current context values? > Or is it a "kind of context variable that is shared among threads?" That was more the direction my mind was going. Context variables

[Python-ideas] Re: Stack-scoped variables

2021-08-19 Thread Thomas Grainger
asyncio.to_thread creates threads that inherit the current context, according to https://www.python.org/dev/peps/pep-0567/#rationale the decimal module should use contextvars for this too ___ Python-ideas mailing list -- python-ideas@python.org To

[Python-ideas] Re: Stack-scoped variables

2021-08-19 Thread Guido van Rossum
Perhaps we need a library for creating/managing threads that inherits all current context values? On Thu, Aug 19, 2021 at 7:48 AM Paul Prescod wrote: > There are certain values that are managed independent of any specific > code-accessible object. The decimal precision is a good example: > >

[Python-ideas] Re: Stack-scoped variables

2021-08-19 Thread Paul Prescod
There are certain values that are managed independent of any specific code-accessible object. The decimal precision is a good example: https://docs.python.org/3/library/decimal.html We can call these context variables. As your code shows, the true "home" of the "prec" value is not some object

[Python-ideas] Re: Stack-scoped variables

2021-08-18 Thread Cameron Simpson
On 18Aug2021 16:30, Paul Prescod wrote: >Let's imagine I have an algorithm which depends on a context variable. > >I write an algorithm (elided below for space) which depends on it. Then I >realize that I can improve the performance of my algorithm by using >concurrent.futures. But my algorithm