classification
Title: Make contextlib.redirect_stdout reentrant
Type: enhancement Stage: resolved
Components: Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: 19330 Superseder:
Assigned To: ncoghlan Nosy List: ncoghlan, python-dev, rhettinger
Priority: normal Keywords: patch

Created on 2013-10-26 06:43 by ncoghlan, last changed 2013-11-03 07:02 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
issue19403_reentrant_redirect_stdout.diff ncoghlan, 2013-10-26 14:18 Make redirect_stdout reentrant review
Messages (4)
msg201318 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-10-26 06:43
I realised making contextlib.redirect_stdout reentrant was actually fairly easy (thread safety is inherently impossible due to the process global side effect). Since making it reentrant makes it more user-friendly, I'll tweak the implementation to work that way.

Need to resolve issue 19330 first, though.

As part of this change, the reusable-but-not-reentrant example in the docs needs to be updated to use contextlib.ExitStack rather than this (that's inherently not reentrant, since all the context managers in the stack would be triggered when the innermost context ends).
msg201358 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-10-26 14:18
I think this change also makes for nicer examples of reentrant (using the updated redirect_stdout) and reusable-but-not-reentrant (using ExitStack) behaviour in the docs.
msg201514 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-10-28 06:11
+1
msg202001 - (view) Author: Roundup Robot (python-dev) Date: 2013-11-03 07:02
New changeset 87d49e2cdd34 by Nick Coghlan in branch 'default':
Close #19403: make contextlib.redirect_stdout reentrant
http://hg.python.org/cpython/rev/87d49e2cdd34
History
Date User Action Args
2013-11-03 07:02:23python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg202001

resolution: fixed
stage: resolved
2013-10-28 06:11:41rhettingersetnosy: + rhettinger
messages: + msg201514
2013-10-26 14:18:22ncoghlansetfiles: + issue19403_reentrant_redirect_stdout.diff
keywords: + patch
messages: + msg201358
2013-10-26 06:44:17ncoghlansetdependencies: + Use public classes for contextlib.suppress and redirect_stdout
2013-10-26 06:43:50ncoghlancreate