1 file, multiple threads

Elbert Lev elbertlev at hotmail.com
Sat Nov 27 09:59:55 EST 2004


"Guyon Morée" <gumuz at NO_looze_SPAM.net> wrote in message news:<41a7000c$0$16489$4d4ebb8e at news.nl.uu.net>...
> If I have multiple threads reading from the same file, would that be a
> problem?
> 
> if yes, how would I solve it?
> 
> Let's say I want to take it a step further and start writing to 1 file form
> multiple threads, how would I solve that?
> 
> 
> thanx,
> 
> Guyon

The sort answer: yes you will. 
The long: how it will hurt you, depends on OS, the sequence of
operations
and the kind of operations.

If you read "next line" (or something like this) or read data from
random positions,
using lock/unlock around seek/read, will solve the problem 
(and maybe defeat the multithreading gain).

Anyway writes may be not seen by readers.

Remember, that for each file OS has one read position and one write
position.
For writing from multiple threads you also needs lock/unlock guard.

You really would be better off if you use Queues in all threads



More information about the Python-list mailing list