[issue36193] Redirected stderr not reset properly when using logging

Karthikeyan Singaravelan report at bugs.python.org
Tue Mar 5 06:57:01 EST 2019


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

A little simplified reproducer :  

import io, contextlib, logging

message = 'dummy test'

with io.StringIO() as sio:
    with contextlib.redirect_stdout(sio), contextlib.redirect_stderr(sio):
        logging.warning(message)
        output = sio.getvalue()
    print(output)

logging.warning(message)


$ python3.7 /tmp/foo.py
WARNING:root:dummy test

--- Logging error ---
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 1036, in emit
    stream.write(msg)
ValueError: I/O operation on closed file
Call stack:
  File "/tmp/foo.py", line 11, in <module>
    logging.warning(message)
Message: 'dummy test'
Arguments: ()

----------
nosy: +xtreak

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36193>
_______________________________________


More information about the Python-bugs-list mailing list