I&#39;ve reviewed the patch on <a href="http://bugs.python.org/issue815646">http://bugs.python.org/issue815646</a> and have uploaded my modified version (mostly test improvements and some formatting to keep C code under 80 columns with proper 8 space tabs).&nbsp; I would have committed it already but I have a sneaking suspicion that its unit test will barf on windows since it could depend on some posix-like file system semantics.<br>
<br>Could someone with a windows build environment please test it as asked in the issue and report back in the tracker?<br><br>thanks!<br>-gps<br><br><div class="gmail_quote">On Wed, Apr 2, 2008 at 11:47 AM, 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;"><div class="Ih2E3d">On Wed, Apr 2, 2008 at 3:17 AM, Antoine Pitrou &lt;<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>&gt; wrote:<br>

&gt; &nbsp;Guido van Rossum &lt;guido &lt;at&gt; <a href="http://python.org" target="_blank">python.org</a>&gt; writes:<br>
&gt; &nbsp;&gt; Your solution (a counter) seems fine except I think perhaps the<br>
&gt; &nbsp;&gt; close() call should not raise IOError -- instead, it should set a flag<br>
&gt; &nbsp;&gt; so that the thread that makes the counter go to zero can close the<br>
&gt; &nbsp;&gt; thread (after all the file got closed while it was being used).<br>
&gt;<br>
&gt; &nbsp;I agree with Gregory: we should be explicit about what happens. I wonder<br>
&gt; &nbsp;what we would gain from that approach - apart from encouraging dangerous<br>
&gt; &nbsp;coding practices :)<br>
&gt; &nbsp;It also depends how far we want to go: I am merely proposing to fix the<br>
&gt; &nbsp;crashes, do we want to provide a &quot;smarter&quot; close() variation that does what<br>
&gt; &nbsp;you suggest for people that want (or need) to take the risk?<br>
<br>
</div>I also agree with Gregory now -- at least on the issue of fclose().<br>
<br>
I think that for other (non-closing) operations we should be fine,<br>
given the Posix requirement that streams have an internal lock. While<br>
multiple threads reading from a file sounds insane, multiple files<br>
writing to a file is pretty common (think of stdout or stderr) and<br>
should be supported.<br>
<div class="Ih2E3d"><br>
&gt; &nbsp;&gt; There are of course other concurrency issues besides close -- what if<br>
&gt; &nbsp;&gt; two threads both try to do I/O on the file? What will the C stdio<br>
&gt; &nbsp;&gt; library do in that case? Are stdio files thread-safe at the C level?<br>
&gt;<br>
&gt; &nbsp;According to the glibc documentation, at<br>
&gt; &nbsp;<a href="http://www.gnu.org/software/libc/manual/html_node/Streams-and-Threads.html" target="_blank">http://www.gnu.org/software/libc/manual/html_node/Streams-and-Threads.html</a> :<br>
&gt;<br>
&gt; &nbsp;« The POSIX standard requires that by default the stream operations are<br>
&gt; &nbsp;atomic. I.e., issuing two stream operations for the same stream in two<br>
&gt; &nbsp;threads at the same time will cause the operations to be executed as if<br>
&gt; &nbsp;they were issued sequentially. The buffer operations performed while<br>
&gt; &nbsp;reading or writing are protected from other uses of the same stream. To do<br>
&gt; &nbsp;this each stream has an internal lock object which has to be (implicitly)<br>
&gt; &nbsp;acquired before any work can be done. »<br>
&gt;<br>
&gt; &nbsp;So according to POSIX rules it should be perfectly safe.<br>
<br>
</div>Cool.<br>
<div class="Ih2E3d"><br>
&gt; &nbsp;In any case, someone would have to try my patch under Windows and OS X and<br>
&gt; &nbsp;see if test_file.py passes without crashing.<br>
<br>
</div>I know Windows has internal locks on stdio. I trust that OSX, being a<br>
BSD descendant, is posix compliant. So I&#39;m not worried about these.<br>
<br>
+1 on your patch, assuming some other developer reviews it and submits it.<br>
<div class="Ih2E3d"><br>
--<br>
--Guido van Rossum (home page: <a href="http://www.python.org/%7Eguido/" target="_blank">http://www.python.org/~guido/</a>)<br>
_______________________________________________<br>
</div><div><div></div><div class="Wj3C7c">Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/greg%40krypto.org" target="_blank">http://mail.python.org/mailman/options/python-dev/greg%40krypto.org</a><br>
</div></div></blockquote></div><br>