https://bugs.python.org/issue42815

https://github.com/python/cpython/pull/24074


I would love to have this in Python 3.10, but the interaction with "decimal" context has a risk I don't know how to evaluate, neither the impact of a new "context" parameter when launching a new thread. It could collide with a "frequently used" parameter name.

I know that we are quite late in 3.10 window since rc1 is planned in a couple of days, but I think this enhancement is sensible. In fact, I discovered it after being annoyed myself with this issue (threads should have their own contexts) and studying the code to write a patch myself.

In particular, "concurrent.futures" threads should have independent contexts, like asyncio futures have. That would allow, for instance, to have a "requests.Session" object per thread since that object is not thread-safe (my use case today) and reuse it in different futures that happens to run in the same thread.

Since "contextvars" is "threading.local" correctly done, let's do it for real.

If legacy code expects a thread to be able to modify parent context, just pass that context to the thread explicitly.

--
Jesús Cea Avión                         _/_/      _/_/_/        _/_/_/
j...@jcea.es - https://www.jcea.es/    _/_/    _/_/  _/_/    _/_/  _/_/
Twitter: @jcea                        _/_/    _/_/          _/_/_/_/_/
jabber / xmpp:j...@jabber.org  _/_/  _/_/    _/_/          _/_/  _/_/
"Things are not so easy"      _/_/  _/_/    _/_/  _/_/    _/_/  _/_/
"My name is Dump, Core Dump"   _/_/_/        _/_/_/      _/_/  _/_/
"El amor es poner tu felicidad en la felicidad de otro" - Leibniz

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/M67OMDBNFN5FLGLO7HZFJ6CUPK5Z4PJE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to