[issue3139] print is not thread safe
Amaury Forgeot d'Arc
report at bugs.python.org
Thu Jun 19 14:28:53 CEST 2008
Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:
The problem is not only about concurrent prints.
It is about invalid pointer passed to a C function.
Here is an example that reliably crashes the interpreter on my windows
machine:
import bz2, threading
bz2c = bz2.BZ2Compressor()
b = bytearray(b"a" * 1000000)
def f():
for x in range(10):
b[:] = b""
b[:] = bytearray(b"a" * 1000000)
threading.Thread(target=f).start()
for x in range(10):
bz2c.compress(b)
bz2c.compress is a slow function, that happens to accept bytearray and
to release the GIL. If the other thread reallocates the bytearray,
bz2c.compress will read invalid data.
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3139>
_______________________________________
More information about the Python-bugs-list
mailing list