New submission from Amaury Forgeot d'Arc <[EMAIL PROTECTED]>:

I found this problem when adding "print" statements to multi-threaded
code. When applying the attached diff to a py3k installation, the output
on screen always contains some garbage.

The following code is an extract of fileio_write (in Modules/_fileio.c),
but the same behavior appears everywhere:

        if (!PyArg_ParseTuple(args, "s#", &ptr, &n))
                return NULL;

        Py_BEGIN_ALLOW_THREADS
        errno = 0;
        n = write(self->fd, ptr, n);
        Py_END_ALLOW_THREADS

io.BufferedWriter calls this function with a bytearray.
In this case, the GIL is released when holding a pointer to the
bytearray data.
But another thread may mutate the bytearray in between, the pointer
becomes stale and can lead to segfaults or funny results.

----------
components: Interpreter Core
files: test_threaded_print.diff
keywords: patch
messages: 68397
nosy: amaury.forgeotdarc
severity: normal
status: open
title: print is not thread safe
type: crash
versions: Python 2.6, Python 3.0
Added file: http://bugs.python.org/file10658/test_threaded_print.diff

_______________________________________
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue3139>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to