Antoine Pitrou added the comment: Note that the module state is only used when no explicit encoding is given to TextIOWrapper(), so the following patch fixes this particular issue:
$ hg di diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -852,7 +852,7 @@ textiowrapper_init(textio *self, PyObjec char *errors = NULL; char *newline = NULL; int line_buffering = 0, write_through = 0; - _PyIO_State *state = IO_STATE; + _PyIO_State *state = NULL; PyObject *res; int r; @@ -891,6 +891,7 @@ textiowrapper_init(textio *self, PyObjec if (encoding == NULL) { /* Try os.device_encoding(fileno) */ PyObject *fileno; + state = IO_STATE; fileno = _PyObject_CallMethodId(buffer, &PyId_fileno, NULL); /* Ignore only AttributeError and UnsupportedOperation */ if (fileno == NULL) { However, since doing I/O at shutdown is not a particularly uncommon operation, we should still fix the general case to at least raise a proper exception. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20037> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com