Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: Status of side-effecting functions in python Date: Mon, 27 Oct 2014 17:14:58 +0200 Organization: A noiseless patient Spider Lines: 27 Message-ID: <87bnoxv91p.fsf@elektro.pacujo.net> References: <438d510f-05ae-47dd-bcda-42a8b777c99b@googlegroups.com> <683c84d8-d916-4b63-b4b2-92cd2763e260@googlegroups.com> <544e2cf2$0$13009$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="26808"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3C7jUPqq8jNHsyzRacczh" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:EH1HFqm/kFZgCtSE37yIr8kCIto= sha1:VdJxUSmXOBKq6S3xGaH9yV23QG0= Xref: csiph.com comp.lang.python:79790 Grant Edwards : > If you really want to make sure that all bytes get written, you _must_ > put all write() calls in a loop that checks the return value and keeps > re-writing any unwritten data. > > And to answer your next question: yes, Unix application programmers > have been complaining about that (perhaps justifiably) since 1970. I wouldn't have it any other way. Now, I have confused the discussion with some misinformation myself. Python2's file.write() doesn't return a value but pushes the whole string out. Python3's file.write() returns the number of *characters* written. I don't know if the number can ever be different from the total number of characters in the string. In POSIX, a write(2) system call on file blocks until all bytes have been passed on to the file system. The only exception (no pun intended) I know is the reception of a signal. Even then, I'm not sure Linux file systems ever cut writes short because of signals. I think the lack of nonblocking file access in Linux is one of the OS's main shortcomings. Python's sockets and pipes don't have write methods. Marko