Technically, that is correct, but IMHO its complete nonsense to share the file object between threads in the first place. If you need the data in two threads, just read the file once and then share the read-only, immutable content. If the file is small or too large to be held in memory at once, just open and read it on demand. This also saves you from having to rewind the file every time you read it.

Am I missing something?
We suspect that his program reads the same file object from different threads. At least this would explain his problem. I agree with you - usually it is not a good idea to share a file object between threads. This is what I told him the first time. But it is not in our hands - he already has a program that needs to be fixed. It might be easier for him to protect read() calls with a lock. Because it can be done automatically, without thinking too much.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to