David Bolen <db3l....@gmail.com> added the comment:

The issue appears to be the temporary flag (O_TEMPORARY) that is used under 
Windows with delete on close temporary files.  That appears to prevent any 
separate access to the file by anyone else including obtaining another 
reference in the same process:

>>> temp = tempfile.NamedTemporaryFile()
>>> temp, temp.name
(<open file '<fdopen>', mode 'w+b' at 0x017958E8>, 'd:\\temp\\tmp44kugh')
>>> other = open(temp.name, 'r')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 13] Permission denied: 'd:\\temp\\tmp44kugh'

Changing the mode (PR 17774) of the temporary file has no effect.  Setting 
delete=False will work, but would defeat the point of using NamedTemporaryFile 
for the cleanup.

I don't see any way to have both auto-delete and the ability to write 
separately to a file under Windows with NamedTemporaryFile.

Perhaps instead use test.support.temp_dir for the overall test, and let it take 
care of the iteration temp files when cleaning up the entire directory?  
Something like:

    with test_support.temp_dir() as td:
        for i in range(self.NUM_FTP_RETRIEVES):
            urllib.FancyURLopener().retrieve(self.FTP_TEST_FILE, 
os.path.join(td, str(i)))

That seems to work fine under Windows.

----------
nosy: +db3l

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue27973>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to