[issue3476] BufferedWriter not thread-safe

Antoine Pitrou report at bugs.python.org
Sat Aug 2 00:08:57 CEST 2008


Antoine Pitrou <pitrou at free.fr> added the comment:

Le vendredi 01 août 2008 à 21:51 +0000, Martin v. Löwis a écrit :
> With the status quo, people have at least a chance of learning that the
> library is not thread-safe. If the shallow problems are resolved, people
> will cry FOUL loudly when they learn about the deep problems.

But the current implementation can also silently produce garbage without
raising an exception. It's only if the context switch happens at a
certain precise point that an exception is raised. If the internal
buffer is mutated without resizing of the backing memory area (or
without any buffer being currently held), there is no exception and
still the behaviour is incorrect.

> Now that print is a function, it's easy to implement
> a version of it that synchronizes all prints.

Well, if that resolution is prefered, I think it should be integrated to
the builtin print function, rather than forcing users to monkeypatch it
(but a debugging facility directly calling sys.stdout.write or
equivalent will not be helped).

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3476>
_______________________________________


More information about the Python-bugs-list mailing list