This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients Ramin Farajpour Cami, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-02-19.09:38:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1613727536.84.0.00625112763705.issue43260@roundup.psfhosted.org>
In-reply-to
Content
The sys.stdout TextIOWrapper is stuck in a bad state. When the write() method is called with an ASCII string, it implements an optimization that stores a reference to the str() object in the internal pending_bytes instead of immediately encoding the string. Subsequently _textiowrapper_writeflush() attempts to create a bytes object for this ASCII string, but PyBytes_FromStringAndSize fails with a memory error. It's stuck in this state because it will never be able to flush the string. 

The first workaround I thought of was to call to detach() to rewrap sys.stdout.buffer with a new TextIOWrapper instance, but detach() attempts to flush and fails. A hacky but simple and effective workaround is to just re-initialize the wrapper. For example:

    sys.stdout.__init__(sys.stdout.buffer, sys.stdout.encoding,
        sys.stdout.errors, None, True)

This clears the internal pending_bytes.
History
Date User Action Args
2021-02-19 09:38:56eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, Ramin Farajpour Cami
2021-02-19 09:38:56eryksunsetmessageid: <1613727536.84.0.00625112763705.issue43260@roundup.psfhosted.org>
2021-02-19 09:38:56eryksunlinkissue43260 messages
2021-02-19 09:38:56eryksuncreate