On 18Aug2021 16:30, Paul Prescod <pres...@gmail.com> 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 will change its behaviour because it does >not inherit the context. Simply trying to parallelize an "embarrassingly >parallel" algorithm changes its behaviour. > >What I really want is a stack-scoped variable: a variable which retains its >value for all child scopes whether in the same thread or not, unless it is >overwritten in a child scope (whether in the same thread or not).
Do you mean a facility for setting an attribute on an object and reversing that when you exit the scope where you set it? I've got a stackattrs context manager I use for that. Example use: # this is on PyPI from cs.context import stackattrs with stackattrs(getcontext(), prec=8): # .prec=8 vals = map(my_algorithm, range(0, 10)) # .prec is whatever it used to be, including absent Otherwise it is not clear to me what you are after. If this isn't what you want, can you describe what's different? Cheers, Cameron Simpson <c...@cskk.id.au> _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/76G7B7DICTKHZRB6QOOAXYYKYDCSSMQS/ Code of Conduct: http://python.org/psf/codeofconduct/