ENOSPC doesn't cause exception?

holger krekel pyth at devel.trillke.net
Fri Sep 27 16:57:04 EDT 2002


Jeff Epler wrote:
> Can someone tell me why this doesn't cause an exception?
> $ python -c print > /dev/full
> 
> (/dev/full is a special device found on at least some kinds of Linux,
> which always returns -ENOSPC when written)
> 
> if I use 'strace', I can see that -ENOSPC is returned from write():
> $ strace -e write python -c print > /dev/full
> write(1, "\n", 1)                       = -1 ENOSPC (No space left on device)
> 
> I would expect this to print something like
> Traceback (most recent call last):
>   File "<string>", line 1, in ?
> OSError: [Errno 28] No space left on device
> 
> I tested this on Python 1.5.2 and Python 2.3a0 CVS, so it doesn't appear
> to be anything new...

very interesting.  If i have a file which contains:

    f = open('/dev/full','w')
    f.write('hallo')
    f.close()

and do 

    python /tmp/q 

i get the expected behaviour (no space ...).  If you leave out 
'f.close()' you don't get the exception any more. 

But even running with 'python -cu print >/dev/full' (stdout is unbuffered)
this doesn't throw an exception. 

hmmm. Wildly guessing, during interpreter shutdown this exception 
(and possibly others) seem to be ignored?!

At least the following code

    class a:
    def __del__(self):
        raise OSError, "hello"
    a1=a()

produces  

[hpk at cobra /tmp]$ python q
Exception exceptions.OSError: <exceptions.OSError instance at 0x813a8b4>
in <bound method a.__del__ of <__main__.a instance at 0x81344fc>> ignored
[hpk at cobra /tmp]$

Couldn't easily find the place in the C-source where this happens, though.

regards,

    holger




More information about the Python-list mailing list