[issue3476] BufferedWriter not thread-safe

2008-12-07 Thread Winfried Plappert
Changes by Winfried Plappert <[EMAIL PROTECTED]>: -- nosy: +wplappert ___ Python tracker <[EMAIL PROTECTED]> ___ ___ Python-bugs-list ma

[issue3476] BufferedWriter not thread-safe

2008-08-14 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Both BufferedReader and BufferedWriter are now fixed in r65686. Perhaps someone wants to open a separate issue for TextIOWrapper... -- resolution: -> fixed status: open -> closed ___ Python tracke

[issue3476] BufferedWriter not thread-safe

2008-08-14 Thread Martin v. Löwis
Martin v. Löwis <[EMAIL PROTECTED]> added the comment: The patch looks fine (as far as it goes). I do think the same should be done to the reader: IO libraries typically provide a promise that concurrent threads can read, and will get the complete stream in an overlapped manner (i.e. each input

[issue3476] BufferedWriter not thread-safe

2008-08-14 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Here is a new patch which simply wraps the current BufferedWriter methods with a lock. It has a test case, and Amaury's example works fine too. Martin, do you think it's fine? (as for BufferedReader, I don't see the use cases for multithread

[issue3476] BufferedWriter not thread-safe

2008-08-01 Thread Martin v. Löwis
Martin v. Löwis <[EMAIL PROTECTED]> added the comment: > 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 hel

[issue3476] BufferedWriter not thread-safe

2008-08-01 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Le vendredi 01 août 2008 à 21:51 +, 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

[issue3476] BufferedWriter not thread-safe

2008-08-01 Thread Martin v. Löwis
Martin v. Löwis <[EMAIL PROTECTED]> 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

[issue3476] BufferedWriter not thread-safe

2008-08-01 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Attaching a new patch with better performance characteristics than my previous one, and the non-blocking test rewritten in a sane way. Some timeit runs: -s "import io; f=io.open('/dev/null', 'wb'); s=b'a'*1" "for i in xrange(100): f.write(s

[issue3476] BufferedWriter not thread-safe

2008-08-01 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Hi, Selon "Martin v. Löwis" <[EMAIL PROTECTED]>: > > I don't think the proposed patch (file11012) makes it thread-safe, and I > believe you cannot get it thread-safe without using thread synchronization. I should have precised that in the c

[issue3476] BufferedWriter not thread-safe

2008-08-01 Thread Martin v. Löwis
Martin v. Löwis <[EMAIL PROTECTED]> added the comment: I don't think the proposed patch (file11012) makes it thread-safe, and I believe you cannot get it thread-safe without using thread synchronization. For example, if two threads simultaneously determine that there is still space left (len(b)

[issue3476] BufferedWriter not thread-safe

2008-07-31 Thread Benjamin Peterson
Benjamin Peterson <[EMAIL PROTECTED]> added the comment: On Thu, Jul 31, 2008 at 9:36 AM, Antoine Pitrou <[EMAIL PROTECTED]> wrote: > > I don't really know. The logic is quite different (and harder to get right) > than > in BufferedReader. I might try to write a list-of-bytes version and do some

[issue3476] BufferedWriter not thread-safe

2008-07-31 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Selon Benjamin Peterson <[EMAIL PROTECTED]>: > > Benjamin Peterson <[EMAIL PROTECTED]> added the comment: > > It seems that as with the quadratic binary buffered reading, the best > solution is the list of bytes which should be especially help

[issue3476] BufferedWriter not thread-safe

2008-07-31 Thread Benjamin Peterson
Benjamin Peterson <[EMAIL PROTECTED]> added the comment: It seems that as with the quadratic binary buffered reading, the best solution is the list of bytes which should be especially helped by your bytes joining optimization. -- nosy: +benjamin.peterson

[issue3476] BufferedWriter not thread-safe

2008-07-31 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Here is a sample implementation (using a fixed-size bytearray) with test. Amaury, would you like to take a look? I'm a bit puzzled by the shady BufferedRandom semantics: though the tests do pass, it's hard to say why e.g. BufferedRandom.tell(

[issue3476] BufferedWriter not thread-safe

2008-07-31 Thread Antoine Pitrou
New submission from Antoine Pitrou <[EMAIL PROTECTED]>: As discovered in #3139, io.BufferedWriter mutates the size of its internal bytearray object. Consequently, invocations of write() from multiple threads can produce exceptions when one thread gets a buffer to the bytearray while the other thr