Message70494
| Author |
pitrou |
| Recipients |
amaury.forgeotdarc, pitrou |
| Date |
2008年07月31日.09:03:10 |
| SpamBayes Score |
0.04073069 |
| Marked as misclassified |
No |
| Message-id |
<1217494992.05.0.604288591509.issue3476@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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 thread tries to resize it. This especially
affects calling print() from multiple threads.
A solution is to use a fixed-size (preallocated) bytearray object.
Another solution is to get rid of the bytearray approach and replace it
with a growing list of immutable bytes objects.
Here is the test script provided by Amaury:
import sys, io, threading
stdout2 = io.open(sys.stdout.fileno(), mode="w")
def f(i):
for i in range(10):
stdout2.write(unicode((x, i)) + '\n')
for x in range(10):
t = threading.Thread(target=f, args=(x,))
t.start()
(with py3k, replace "stdout2.write" with a simple "print") |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2008年07月31日 09:03:12 | pitrou | set | recipients:
+ pitrou, amaury.forgeotdarc |
| 2008年07月31日 09:03:12 | pitrou | set | messageid: <1217494992.05.0.604288591509.issue3476@psf.upfronthosting.co.za> |
| 2008年07月31日 09:03:11 | pitrou | link | issue3476 messages |
| 2008年07月31日 09:03:10 | pitrou | create |
|