Serhiy Storchaka added the comment: Thank you for your report and patch Sebastian.
In Python 3 the solution can be simpler, just move the line "_PyObject_GC_UNTRACK(self);" above the line "textiowrapper_clear(self);". But calling PyObject_ClearWeakRefs() also should be moved up. Otherwise half-destroyed TextIOWrapper instance can be accessed via weak references. Following patches do this (and small refactoring). ---------- versions: +Python 3.5, Python 3.6, Python 3.7 Added file: http://bugs.python.org/file45274/textiowrapper_clear-3.5.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28387> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com