def default():
"""
Obtain the global default instance of TemporaryDirectory, creating
it first if necessary. Failures are propagated to caller. Most
callers are expected to use this function rather than
instantiating TemporaryDirectory directly, unless they explicitly
desdire to have their "own" directory for some reason.
This function is thread-safe.
"""
global _defaultLock
global _defaultInstance
_defaultLock.acquire()
try:
if _defaultInstance is None or _defaultInstance.dir() is None:
_defaultInstance = TemporaryDirectory(temproot=globals.temproot)
# set the temp dir to be the default in tempfile module from now on
tempfile.tempdir = _defaultInstance.dir()
return _defaultInstance
finally:
_defaultLock.release()
评论列表
文章目录