Author amaury.forgeotdarc
Recipients amaury.forgeotdarc
Date 2008-06-19.10:06:45
SpamBayes Score 0.280307
Marked as misclassified No
Message-id <1213870014.47.0.920261148604.issue3139@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2008-06-19 10:06:55amaury.forgeotdarcsetspambayes_score: 0.280307 -> 0.280307
recipients: + amaury.forgeotdarc
2008-06-19 10:06:54amaury.forgeotdarcsetspambayes_score: 0.280307 -> 0.280307
messageid: <1213870014.47.0.920261148604.issue3139@psf.upfronthosting.co.za>
2008-06-19 10:06:53amaury.forgeotdarclinkissue3139 messages
2008-06-19 10:06:52amaury.forgeotdarccreate