I have the following test script:

import asyncio
import tempfile

@asyncio.coroutine
def error():
    raise KeyboardInterrupt()

@asyncio.coroutine
def main():
    with tempfile.TemporaryDirectory():
        yield from asyncio.gather(error())  # gather() is important here

loop = asyncio.get_event_loop()
loop.run_until_complete(main())


When I run that, I get several tracebacks in a row, and one of them is 
inexplicable to me:

Exception ignored in: <generator object main at 0x7fccf7a48ee8>
Traceback (most recent call last):
  File "test.py", line 11, in main
  File "/usr/lib/python3.4/tempfile.py", line 691, in __exit__
  File "/usr/lib/python3.4/tempfile.py", line 697, in cleanup
  File "/usr/lib/python3.4/shutil.py", line 454, in rmtree
  File "/usr/lib/python3.4/shutil.py", line 452, in rmtree
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpl2z0vwdy'


When the TemporaryDirectory context manager exits, it tries to clean up the 
directory it created. In this case, something appears to have already 
deleted that directory. There's no other rmdir() or anything like that in 
the script, so I'm confused. This part of the traceback goes away if I 
remove the gather() in there and instead yield directly from my error() 
coro. This also doesn't repro if I throw a RuntimeError instead of a 
KeyboardInterrupt.

Could gather() be removing a directory? Or maybe making my context manager 
exit twice?

Reply via email to