Newbie prob: How to write a file with 3 threads?

est electronixtar at gmail.com
Mon May 7 03:13:46 EDT 2007


On May 7, 5:12 am, MRAB <goo... at mrabarnett.plus.com> wrote:
> On May 6, 9:51 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:> In <1178440537.257526.40... at y5g2000hsa.googlegroups.com>, est wrote:
> > > I need to write a file using 3 threads simutaniously, e.g. Thread 1
> > > write the first byte of test.bin with an "a", second thread write the
> > > second byte "b", third thread write the third byte "c". Anyone could
> > > give a little example on how to do that?
>
> > Simplest solution is: don't do that.  Write from one thread and send the
> > date from the other threads via a `Queue.Queue` to the writing thread.
> > Send the number of the thread with the data so the writer thread knows in
> > which order the data has to be written.
>
> [snip]
> Or have a `Queue.Queue` for each source thread and make the writer
> thread read from each in turn.


I'll try Queue.Queue, thank you. I didn't expect that multithread
write a file is so troublesome




More information about the Python-list mailing list