Message387299
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. |
|
Date |
User |
Action |
Args |
2021-02-19 09:38:56 | eryksun | set | recipients:
+ eryksun, paul.moore, tim.golden, zach.ware, steve.dower, Ramin Farajpour Cami |
2021-02-19 09:38:56 | eryksun | set | messageid: <1613727536.84.0.00625112763705.issue43260@roundup.psfhosted.org> |
2021-02-19 09:38:56 | eryksun | link | issue43260 messages |
2021-02-19 09:38:56 | eryksun | create | |
|