This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: traceback when using tempfile module on windows
Type: crash Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Hassan El Karouni, vstinner
Priority: normal Keywords:

Created on 2015-08-27 09:15 by Hassan El Karouni, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg249228 - (view) Author: Hassan El Karouni (Hassan El Karouni) Date: 2015-08-27 09:15
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tempfile.mkstemp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\tempfile.py", line 308, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags)
  File "C:\Python27\lib\tempfile.py", line 240, in _mkstemp_inner
    _set_cloexec(fd)
  File "C:\Python27\lib\tempfile.py", line 50, in _set_cloexec
    flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
AttributeError: 'module' object has no attribute 'F_GETFD'


On line 51 in tempfile.py, an AttributeError exception is not caught. The problem is caused by the fact that on Windows, the fcntl module is supposed not to exist, but in my case, a dummy module with the same name was put on the path. This means that line 50 is run thru when making the mkstemp() call.
The fix is to catch the AttributeError exception on line 51.
The bug might also affect Python 3 but this is to be checked.
msg249229 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-08-27 09:42
Hi, do you have a file called fcntl.py in your project?

Try:

>>> import fcntl
>>> fcntl.__file__
'/usr/lib64/python2.7/lib-dynload/fcntlmodule.so'

This module should be available on Windows.
msg249230 - (view) Author: Hassan El Karouni (Hassan El Karouni) Date: 2015-08-27 10:16
fcntl.__file__  returns  "fcntl.py". The file is located under site-packages.
The contents of the file are:
def fcntl(fd, op, arg=0):
    return 0
        
def ioctl(fd, op, arg=0, mutable_flag=True):
    if mutable_flag:
        return 0
    else:
        return ""
    
def flock(fd, op):
    return
      
def lockf(fd, operation, length=0, start=0, whence=0):
    return
msg249231 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-08-27 11:31
> fcntl.__file__  returns  "fcntl.py". The file is located under site-packages.

Ok, it's not a bug in Python, but in your local setup. Rename this file to fcntl.py.old, it should fix your issue.
History
Date User Action Args
2022-04-11 14:58:20adminsetgithub: 69132
2015-08-27 11:31:59vstinnersetstatus: open -> closed
resolution: not a bug
messages: + msg249231
2015-08-27 10:16:06Hassan El Karounisetmessages: + msg249230
2015-08-27 09:42:35vstinnersetnosy: + vstinner
messages: + msg249229
2015-08-27 09:15:35Hassan El Karounicreate