Message287888
Here is a very short program to demonstrate what I'm seeing:
>>> import tempfile
>>> import os
>>> with tempfile.NamedTemporaryFile(delete=True) as fp:
... print(fp.name)
... os.system('rm {}'.format(fp.name))
/tmp/tmpomw0udc6
0
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/usr/local/lib/python3.6/tempfile.py", line 502, in __exit__
self.close()
File "/usr/local/lib/python3.6/tempfile.py", line 509, in close
self._closer.close()
File "/usr/local/lib/python3.6/tempfile.py", line 446, in close
unlink(self.name)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpomw0udc6'
In my specific use case, I am shelling out to another program (binutils' objcopy) and passing the path of the NamedTemporaryFile as the output file. objcopy apparently deletes the output file if it encounters an error, which causes NamedTemporaryFile's exit method to fail when it tries to delete the file.
While I can work around this by using delete=False and manually doing the cleanup on my own, it's less elegant than being able to rely on the normal context manager exit. |
|
Date |
User |
Action |
Args |
2017-02-15 21:21:19 | richardxia | set | recipients:
+ richardxia |
2017-02-15 21:21:19 | richardxia | set | messageid: <1487193679.14.0.35599130933.issue29573@psf.upfronthosting.co.za> |
2017-02-15 21:21:19 | richardxia | link | issue29573 messages |
2017-02-15 21:21:18 | richardxia | create | |
|