[issue31976] Segfault when closing BufferedWriter from a different thread

Benjamin Fogle report at bugs.python.org
Tue Nov 7 23:27:27 EST 2017


New submission from Benjamin Fogle <benfogle at gmail.com>:

To reproduce:
```
import threading
import io
import time
import _pyio

class MyFileIO(io.FileIO):
    def flush(self):
        # Simulate a slow flush. Slow disk, etc.
        time.sleep(0.25)
        super().flush()

raw = MyFileIO('test.dat', 'wb')
#fp = _pyio.BufferedWriter(raw)
fp = io.BufferedWriter(raw)
t1 = threading.Thread(target=fp.close)
t1.start()
time.sleep(0.1) # Ensure t1 is sleeping in fp.close()/raw.flush()
fp.write(b'test')
t1.join()
```

_pyio.BufferedWriter ignores the error completely rather than throwing a ValueError("write to closed file").

----------
components: Interpreter Core
messages: 305803
nosy: benfogle
priority: normal
severity: normal
status: open
title: Segfault when closing BufferedWriter from a different thread
versions: Python 3.6, Python 3.7

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


More information about the Python-bugs-list mailing list