From 632e6c392141dfed0711624139ce0bc3724ff947 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Thu, 25 Apr 2013 10:39:27 -0700 Subject: [PATCH] Perform thread locking in remove() --- mmstats/models.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mmstats/models.py b/mmstats/models.py index cd32d53..cb2c061 100644 --- a/mmstats/models.py +++ b/mmstats/models.py @@ -125,13 +125,14 @@ def flush(self, async=False): _mmap.msync(self._mm_ptr, self._size, async) def remove(self): - # Perform regular removal of this process/thread's own file. - self._remove() - # Then ensure we clean up any forgotten thread-related files, if - # applicable. Ensure {PID} exists, for safety's sake - better to not - # cleanup than to cleanup multiple PIDs' files. - if '{PID}' in self._filename and '{TID}' in self._filename: - self._remove_stale_thread_files() + with threading.Lock(): + # Perform regular removal of this process/thread's own file. + self._remove() + # Then ensure we clean up any forgotten thread-related files, if + # applicable. Ensure {PID} exists, for safety's sake - better to not + # cleanup than to cleanup multiple PIDs' files. + if '{PID}' in self._filename and '{TID}' in self._filename: + self._remove_stale_thread_files() def _remove_stale_thread_files(self): # The originally given (to __init__) filename string, containing