Tim Peters  committed a4abe17

Windows fix: When PYTHONCASEOK is set, or for any other reason imports
are satisfied in a case-insensitive manner, the attempt to import (the
non-existent) fcntl gets satisfied by instead, and the tempfile
module defines a Unix-specific _set_cloexec() function in that case. As
a result, temp files can't be created then (blows up with an AttributeError
trying to reference fcntl.fcntl). This just popped up in the spambayes
project, where there is no apparent workaround (which is why I'm pushing
this in now).

  • Participants
  • Parent commits fe499bc
  • Branches legacy-trunk

Comments (0)

Files changed (2)

File Lib/

     import fcntl as _fcntl
+    # If PYTHONCASEOK is set on Windows, stinking gets
+    # imported, and we don't get an ImportError then.  Provoke
+    # an AttributeError instead in that case.
+    _fcntl.fcntl
+except (ImportError, AttributeError):
+    def _set_cloexec(fd):
+        pass
     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)
-except (ImportError, AttributeError):
-    def _set_cloexec(fd):
-        pass
     import thread as _thread
+- The tempfile module could do insane imports on Windows if PYTHONCASEOK
+  was set, making temp file creation impossible.  Repaired.