[Python-ideas] Making sys.std* thread-local

Antony Lee antony.lee at berkeley.edu
Thu Feb 6 22:37:50 CET 2014


The recent discussion about lexical vs. dynamic scoping reminded me of the
following issue, that plagues e.g. the new contextlib.redirect_stdout
context manager: the standard file-like objects sys.std* are global instead
of thread-local, making their manipulation unsafe in multithreaded programs
(this issue is related to lexical vs dynamic scoping because in a language
with (optional) dynamic scoping, these objects can be made dynamically
scoped, thus solving the issue).
Of course, changing sys.std* to being thread-local would be backwards
incompatible, but perhaps some new objects, e.g. sys.thread_local_std*,
could be added to sys, with print() and related functions using
sys.thread_local_std* if it is set and sys.std* otherwise.
Antony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140206/461a7944/attachment.html>


More information about the Python-ideas mailing list