[Python-bugs-list] [ python-Bugs-821896 ] _set_cloexec of tempfile.py uses incorrect error handling

SourceForge.net noreply at sourceforge.net
Sun Nov 2 13:13:42 EST 2003


Bugs item #821896, was opened at 2003-10-11 21:49
Message generated for change (Comment added) made by aleax
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=821896&group_id=5470

Category: Python Library
>Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Per Cederqvist (ceder)
>Assigned to: Alex Martelli (aleax)
Summary: _set_cloexec of tempfile.py uses incorrect error handling

Initial Comment:
The _set_cloexec function of tempfile.py looks like
this on Unix-like platforms:

    def _set_cloexec(fd):
        flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
        if flags >= 0:
            # flags read successfully, modify
            flags |= _fcntl.FD_CLOEXEC
            _fcntl.fcntl(fd, _fcntl.F_SETFD, flags)

However, fcntl.fcntl() will never return a negative
value.  If an error occurs, it will instead raise an
exception:

>>> fcntl.fcntl(10, fcntl.F_GETFD, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 9] Bad file descriptor

(This was tested on Linux.)

I doubt that this will ever cause any problems, except
if somebody uses the code as an example and copies the
error to their own code.

----------------------------------------------------------------------

>Comment By: Alex Martelli (aleax)
Date: 2003-11-02 19:13

Message:
Logged In: YES 
user_id=60314

your remarks are entirely correct.  I have changed the incorrect test into a try/except IOError, and committed the change on the 2.3 maintenance branch in CVS.  Thanks!


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=821896&group_id=5470



More information about the Python-bugs-list mailing list