[issue3476] BufferedWriter not thread-safe

Martin v. Löwis report at bugs.python.org
Fri Aug 1 23:51:03 CEST 2008


Martin v. Löwis <martin at v.loewis.de> added the comment:

> I should have precised that in the context of this issue, "thread-safe" does not
> mean "produces perfectly correct output" but simply "does not raise exceptions
> when using the same buffered object from two different threads".

In that case, I'm -1 for this patch. Raising exceptions is much more
preferable to silently losing data, or writing garbage.

> The former would be preferable but is not required, IMHO, for a buffered IO library; the
> latter is much more critical because as Amaury points out, you otherwise get
> exceptions when printing e.g. debut output from multiple threads.

And that's a good thing, when using a library that is not thread-safe.

Either the library provides thread-safety, or it doesn't. If it doesn't,
it's the application's responsibility to not use the library from
multiple threads, or protect all access with appropriate
synchronization. Now that print is a function, it's easy to implement
a version of it that synchronizes all prints.

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.

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


More information about the Python-bugs-list mailing list