diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 472fd83155b2..1405a7f74243 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -47,8 +47,9 @@ def _set_cloexec(fd): pass else: def _set_cloexec(fd): - flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0) - if flags >= 0: + try: flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0) + except IOError: pass + else: # flags read successfully, modify flags |= _fcntl.FD_CLOEXEC _fcntl.fcntl(fd, _fcntl.F_SETFD, flags)