diff options
author | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2008-09-16 13:11:58 +0000 |
---|---|---|
committer | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2008-09-16 13:11:58 +0000 |
commit | c5432bb02546ac5180c8fa4e6cfcc5b8e07ff6d3 (patch) | |
tree | 27ac987c3a41af221beeb9fc184ecb4bedc9e19e /fs/tempfs.py | |
parent | ac051cb8790e75ca6fc893b327e32ba50543691a (diff) | |
download | pyfilesystem-git-c5432bb02546ac5180c8fa4e6cfcc5b8e07ff6d3.tar.gz |
Various changes..
Diffstat (limited to 'fs/tempfs.py')
-rw-r--r-- | fs/tempfs.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/fs/tempfs.py b/fs/tempfs.py index 6f345d4..8fd1609 100644 --- a/fs/tempfs.py +++ b/fs/tempfs.py @@ -9,7 +9,7 @@ class TempFS(OSFS): """Create a Filesystem in a tempory directory (with tempfile.mkdtemp), and removes it when the TempFS object is cleaned up.""" - def __init__(self, identifier=None): + def __init__(self, identifier=None, thread_syncronize=True): """Creates a temporary Filesystem identifier -- A string that is included in the name of the temporary directory, @@ -18,18 +18,25 @@ class TempFS(OSFS): """ self._temp_dir = tempfile.mkdtemp(identifier or "TempFS") self._cleaned = False - OSFS.__init__(self, self._temp_dir) + OSFS.__init__(self, self._temp_dir, thread_syncronize=thread_syncronize) def __str__(self): return '<TempFS in "%s">' % self._temp_dir + def __unicode__(self): + return uncode(self.__str__()) + def _cleanup(self): """Called by __del__ to remove the temporary directory. Can be called directly, - but it is probably not advisable.""" + but it is probably not neccesary.""" if not self._cleaned: - rmtree(self._temp_dir) - self._cleaned = True + self._lock.acquire() + try: + rmtree(self._temp_dir) + self._cleaned = True + finally: + self._lock.release() def __del__(self): self._cleanup() |