Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79780

Re: Status of side-effecting functions in python

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '"this': 0.03; 'assuming': 0.09; 'bytes,': 0.09; 'method,': 0.09; 'okay': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; '(file': 0.16; 'exception?': 0.16; 'exceptions,': 0.16; 'finds': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ioerror,': 0.16; 'non- blocking': 0.16; 'requested.': 0.16; 'roy': 0.16; 'throw': 0.16; 'subject:python': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'properly': 0.19; 'written,': 0.19; '>>>': 0.22; 'python?': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'byte': 0.24; 'bytes': 0.24; 'documented': 0.24; 'lets': 0.24; 'tells': 0.24; 'mon,': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'second': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'rest': 0.29; 'raise': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; "d'aprano": 0.31; 'once,': 0.31; 'steven': 0.31; 'handled': 0.32; 'supposed': 0.32; 'option': 0.32; 'third': 0.33; 'skip:d 20': 0.34; 'problem': 0.35; "can't": 0.35; 'common': 0.35; 'possible.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'disk': 0.36; 'should': 0.36; 'error.': 0.37; 'half': 0.37; 'wrong': 0.37; 'too': 0.37; 'being': 0.38; 'writes': 0.38; 'whatever': 0.38; 'pm,': 0.38; 'expect': 0.39; 'though,': 0.39; 'unable': 0.39; 'space': 0.40; 'how': 0.40; 'catch': 0.60; 'temporarily': 0.60; 'most': 0.60; 'tell': 0.60; 'no.': 0.61; "you're": 0.61; 'you.': 0.62; 'back': 0.62; 'more': 0.64; 'yes': 0.68; 'smith': 0.68; 'genuine': 0.78; 'choose.': 0.84; 'partial': 0.84; 'absolutely': 0.87; 'device,': 0.91; 'write()': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=qcFM58C9WjpoBin/RVxa5wPppn8gpQCc6UkKJXP0WDA=; b=p/hr/rdK6AbMnaih2WZYy5rw4SxesotpwpRWyN9qaRhhBa18BJUELD3Di97Q9P8+tJ H6biDk6Voab4Bx39VgjDPV+ttreYsEb1JdsPWLeCck3mVWU6zT/8bBhx/VVbJ0R7zka8 lwmTGckmg49fWuqdvQODpcytkAMtBw0nS6wc44BPqzQrIfCdkwgaZo6Hu+ZOYzQe+BcW l5SMzottofULaWWaPw/eClTVolozvP3paivTUTDP55ncPL6PNwPgjjNX1Idjcl0vTj+b izPr12zBBNPSp2giKeGWJH8FEPNRTotzCsYTXFfZ1BI3PyHraAbjgsXZQ1oEkleNdQO2 BSLA==
MIME-Version 1.0
X-Received by 10.107.136.68 with SMTP id k65mr8395192iod.43.1414410252555; Mon, 27 Oct 2014 04:44:12 -0700 (PDT)
In-Reply-To <544e2cf2$0$13009$c3e8da3$5496439d@news.astraweb.com>
References <c5e3a7e7-5997-47ee-8e81-759f2342c87a@googlegroups.com> <mailman.15174.1414273325.18130.python-list@python.org> <438d510f-05ae-47dd-bcda-42a8b777c99b@googlegroups.com> <m2itm2$l5r$1@dont-email.me> <683c84d8-d916-4b63-b4b2-92cd2763e260@googlegroups.com> <roy-8A6FEF.17562126102014@news.panix.com> <544e2cf2$0$13009$c3e8da3$5496439d@news.astraweb.com>
Date Mon, 27 Oct 2014 22:44:12 +1100
Subject Re: Status of side-effecting functions in python
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15235.1414410255.18130.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414410255 news.xs4all.nl 2861 [2001:888:2000:d::a6]:59312
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79780

Show key headers only | View raw


On Mon, Oct 27, 2014 at 10:30 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Roy Smith wrote:
>
>>> Yes and no. If something goes wrong in a .write() method,
>>> is not Python supposed to raise an error? (!)
>>
>> Define "wrong".  It is not an error for a write() call to consume fewer
>> bytes than were requested.
>
> It's not? I'm asking a genuine question here, not a rhetorical one. I would
> expect that if I ask to write 2 bytes, and only 1 byte is written, that
> absolutely is an error. Under what circumstances is it okay for write() to
> throw data away?
>
>> How would you expect this to be handled in Python?  Raise
>> DataPartiallyWrittenError?
>
> I would expect it to raise an IOError, most likely with one of the following
> error codes:
>
> * errno.EIO (physical input/output error)
>
> * errno.EFBIG (file is too large)
>
> * errno.ENOSPC (no space left on device, disk is full)

You're assuming the condition, whatever it is, is permanent. The most
common reason for write() to be temporarily unable to write everything
is a non-blocking socket, pipe, or somesuch. It writes as much as it
can, tells you how much that is, and lets you buffer the rest or deal
with it in whatever other way you choose.

If it is permanent, though, then yes, it should tell you. But what if
you ask it to write a megabyte, it writes half of it, and then finds
that there's no space on the disk? Should it:

1) Back out the write and raise an exception?
2) Write part of the data and raise an exception?
3) Write part of the data and NOT raise an exception?

All three make sense. The third one is an option only if it's
documented as being able to tell you about partial writes. The second
has a problem in that you can't necessarily communicate "this is how
much I wrote" properly while also signalling the exception (imagine if
one function calls write() more than once, and it doesn't catch any
exceptions, just lets them bubble up). And backing out a write isn't
always possible. So what's to do?

ChrisA

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Status of side-effecting functions in python Rustom Mody <rustompmody@gmail.com> - 2014-10-25 10:27 -0700
  Re: Status of side-effecting functions in python Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-10-25 23:41 +0200
    Re: Status of side-effecting functions in python Dan Sommers <dan@tombstonezero.net> - 2014-10-25 22:22 +0000
      Re: Status of side-effecting functions in python Terry Reedy <tjreedy@udel.edu> - 2014-10-25 18:53 -0400
    Re: Status of side-effecting functions in python wxjmfauth@gmail.com - 2014-10-26 00:45 -0700
      Re: Status of side-effecting functions in python Dan Sommers <dan@tombstonezero.net> - 2014-10-26 13:41 +0000
        Re: Status of side-effecting functions in python Rustom Mody <rustompmody@gmail.com> - 2014-10-26 07:53 -0700
        Re: Status of side-effecting functions in python wxjmfauth@gmail.com - 2014-10-26 09:26 -0700
          Re: Status of side-effecting functions in python Marko Rauhamaa <marko@pacujo.net> - 2014-10-26 18:50 +0200
          Re: Status of side-effecting functions in python Roy Smith <roy@panix.com> - 2014-10-26 17:56 -0400
            Re: Status of side-effecting functions in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-27 22:30 +1100
              Re: Status of side-effecting functions in python Chris Angelico <rosuav@gmail.com> - 2014-10-27 22:44 +1100
              Re: Status of side-effecting functions in python Roy Smith <roy@panix.com> - 2014-10-27 09:28 -0400
              Re: Status of side-effecting functions in python Grant Edwards <invalid@invalid.invalid> - 2014-10-27 14:45 +0000
                Re: Status of side-effecting functions in python Marko Rauhamaa <marko@pacujo.net> - 2014-10-27 17:14 +0200
                Re: Status of side-effecting functions in python Nobody <nobody@nowhere.invalid> - 2014-10-28 03:52 +0000
                Re: Status of side-effecting functions in python Marko Rauhamaa <marko@pacujo.net> - 2014-10-28 11:07 +0200
                Re: Status of side-effecting functions in python Marko Rauhamaa <marko@pacujo.net> - 2014-10-28 11:10 +0200
                .write() behavior Alan Bawden <alan@scooby-doo.csail.mit.edu> - 2014-10-29 01:06 -0400
                Re: .write() behavior Marko Rauhamaa <marko@pacujo.net> - 2014-10-29 08:00 +0200
                Re: .write() behavior Alan Bawden <alan@scooby-doo.csail.mit.edu> - 2014-10-31 16:32 -0400
    Re: Status of side-effecting functions in python Grant Edwards <invalid@invalid.invalid> - 2014-10-27 14:22 +0000

csiph-web