def __init__(self) -> None:
'''Create a temporary file.
The path to the file can be retrieved from the `name` attribute on the returned object.
To ensure proper removal of the file after use,
make sure to call `cleanup()` on the returned object, or use it as a context manager.
'''
fd, self.name = tempfile.mkstemp(prefix='pyaspio_')
# Ideally, we would use this file descriptor instead of reopening the file from the path later,
# but then we do not know whether the file descriptor has already been closed.
# (possible problems: we might leak a file descriptor, or close it twice (thus risking to close another unrelated file))
os.close(fd)
self._cleanup_warning = weakref.finalize(self, _warn_cleanup, type(self).__name__, self.name) # type: ignore
self._cleanup_warning.atexit = True
评论列表
文章目录