<br><br><div class="gmail_quote">On Tue, Apr 1, 2008 at 5:09 PM, Guido van Rossum &lt;<a href="mailto:guido@python.org">guido@python.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This is not something that keeps me awake at night, but I am aware of<br>
it. Your solution (a counter) seems fine except I think perhaps the<br>
close() call should not raise IOError -- instead, it should set a flag<br>
so that the thread that makes the counter go to zero can close the<br>
thread (after all the file got closed while it was being used).<br>
</blockquote><div><br>No, raising IOError is the right thing to do here.<br><br>The problem is that calling close on a file implies that the close actually completed in the OS when it returns.&nbsp; The call should not return until the file object has actually been closed in the underlying layers.&nbsp; You can&#39;t leave it for later to be done by one of the other currently operating threads as you violate the close semantics and lose direct indication of an error that occurred during close.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
There are of course other concurrency issues besides close -- what if<br>
two threads both try to do I/O on the file? What will the C stdio<br>
library do in that case? Are stdio files thread-safe at the C level?<br>
So (classically contradicting myself while I think the problem over<br>
more) perhaps any I/O operation should be disallowed while the file is<br>
in use by another thread?<br>
</blockquote><div><br>that does sound like the safest thing to do...<br><br></div>-gps<br></div><br>