[pypy-svn] r46638 - pypy/dist/pypy/tool
arigo at codespeak.net
arigo at codespeak.net
Sat Sep 15 15:38:24 CEST 2007
Author: arigo
Date: Sat Sep 15 15:38:24 2007
New Revision: 46638
Modified:
pypy/dist/pypy/tool/cache.py
Log:
Protect cache building in a multithreaded py.py.
Modified: pypy/dist/pypy/tool/cache.py
==============================================================================
--- pypy/dist/pypy/tool/cache.py (original)
+++ pypy/dist/pypy/tool/cache.py Sat Sep 15 15:38:24 2007
@@ -25,6 +25,9 @@
# Be sure to call the parent __init__() if you override it.
#
+from threading import RLock
+lock = RLock() # multithreading protection
+
class Cache(object):
def __init__(self):
@@ -32,20 +35,24 @@
self._building = {}
def getorbuild(self, key):
+ lock.acquire()
try:
- return self.content[key]
- except KeyError:
- if key in self._building:
- raise Exception, "%s recursive building of %r" % (
- self, key)
- self._building[key] = True
try:
- result = self._build(key)
- self.content[key] = result
- finally:
- del self._building[key]
- self._ready(result)
- return result
+ return self.content[key]
+ except KeyError:
+ if key in self._building:
+ raise Exception, "%s recursive building of %r" % (
+ self, key)
+ self._building[key] = True
+ try:
+ result = self._build(key)
+ self.content[key] = result
+ finally:
+ del self._building[key]
+ self._ready(result)
+ return result
+ finally:
+ lock.release()
getorbuild._annspecialcase_ = "specialize:memo"
def _ready(self, result):
More information about the Pypy-commit
mailing list