I'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). 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 <<a href="mailto:guido@python.org">guido@python.org</a>> 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 <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>> wrote:<br>
> Guido van Rossum <guido <at> <a href="http://python.org" target="_blank">python.org</a>> writes:<br>
> > 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>
><br>
> I agree with Gregory: we should be explicit about what happens. I wonder<br>
> what we would gain from that approach - apart from encouraging dangerous<br>
> coding practices :)<br>
> It also depends how far we want to go: I am merely proposing to fix the<br>
> crashes, do we want to provide a "smarter" close() variation that does what<br>
> 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>
> > 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>
><br>
> According to the glibc documentation, at<br>
> <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>
><br>
> « The POSIX standard requires that by default the stream operations are<br>
> atomic. I.e., issuing two stream operations for the same stream in two<br>
> threads at the same time will cause the operations to be executed as if<br>
> they were issued sequentially. The buffer operations performed while<br>
> reading or writing are protected from other uses of the same stream. To do<br>
> this each stream has an internal lock object which has to be (implicitly)<br>
> acquired before any work can be done. »<br>
><br>
> So according to POSIX rules it should be perfectly safe.<br>
<br>
</div>Cool.<br>
<div class="Ih2E3d"><br>
> In any case, someone would have to try my patch under Windows and OS X and<br>
> 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'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>