[pypy-svn] r16459 - pypy/dist/pypy/module/thread
arigo at codespeak.net
arigo at codespeak.net
Thu Aug 25 12:46:13 CEST 2005
Author: arigo
Date: Thu Aug 25 12:46:07 2005
New Revision: 16459
Modified:
pypy/dist/pypy/module/thread/gil.py
pypy/dist/pypy/module/thread/os_local.py
pypy/dist/pypy/module/thread/threadlocals.py
Log:
For now, use string-keyed instead of integer-keyed dictionaries in
module/thread, in an effort to make it translatable.
Modified: pypy/dist/pypy/module/thread/gil.py
==============================================================================
--- pypy/dist/pypy/module/thread/gil.py (original)
+++ pypy/dist/pypy/module/thread/gil.py Thu Aug 25 12:46:07 2005
@@ -15,6 +15,7 @@
"""A version of OSThreadLocals that enforces a GIL."""
def __init__(self):
+ OSThreadLocals.__init__(self)
self.GIL = thread.allocate_lock()
def enter_thread(self, space):
Modified: pypy/dist/pypy/module/thread/os_local.py
==============================================================================
--- pypy/dist/pypy/module/thread/os_local.py (original)
+++ pypy/dist/pypy/module/thread/os_local.py Thu Aug 25 12:46:07 2005
@@ -17,16 +17,18 @@
self.space = space
self.initargs = initargs
ident = thread.get_ident()
- self.dicts = {ident: space.newdict([])}
+ # XXX use string-keyed dicts only for now
+ self.dicts = {str(ident): space.newdict([])}
def getdict(self):
ident = thread.get_ident()
+ key = str(ident)
try:
- w_dict = self.dicts[ident]
+ w_dict = self.dicts[key]
except KeyError:
# create a new dict for this thread
space = self.space
- w_dict = self.dicts[ident] = space.newdict([])
+ w_dict = self.dicts[key] = space.newdict([])
# call __init__
try:
w_self = space.wrap(self)
@@ -35,7 +37,7 @@
space.call_args(w_init, self.initargs.prepend(w_self))
except:
# failed, forget w_dict and propagate the exception
- del self.dicts[ident]
+ del self.dicts[key]
raise
# ready
space.threadlocals.atthreadexit(space, finish_thread, self)
@@ -47,7 +49,7 @@
space.wrap("setting dictionary to a non-dict"))
self.getdict() # force a dict to exist first
ident = thread.get_ident()
- self.dicts[ident] = w_dict
+ self.dicts[str(ident)] = w_dict
def descr_local__new__(space, w_subtype, __args__):
# XXX check __args__
@@ -70,4 +72,4 @@
def finish_thread(w_obj):
assert isinstance(w_obj, Local)
ident = thread.get_ident()
- del w_obj.dicts[ident]
+ del w_obj.dicts[str(ident)]
Modified: pypy/dist/pypy/module/thread/threadlocals.py
==============================================================================
--- pypy/dist/pypy/module/thread/threadlocals.py (original)
+++ pypy/dist/pypy/module/thread/threadlocals.py Thu Aug 25 12:46:07 2005
@@ -10,15 +10,17 @@
a thread finishes. This works as long as the thread was started by
os_thread.bootstrap()."""
- _valuedict = {} # {thread_ident: ExecutionContext()}
+ def __init__(self):
+ # XXX use string-keyed dicts only for now
+ self._valuedict = {} # {str(thread_ident): ExecutionContext()}
def getvalue(self):
ident = thread.get_ident()
- return self._valuedict.get(ident, None)
+ return self._valuedict.get(str(ident), None)
def setvalue(self, value):
ident = thread.get_ident()
- self._valuedict[ident] = value
+ self._valuedict[str(ident)] = value
def enter_thread(self, space):
"Notification that the current thread is just starting."
@@ -35,7 +37,7 @@
finally:
ident = thread.get_ident()
try:
- del self._valuedict[ident]
+ del self._valuedict[str(ident)]
except KeyError:
pass
More information about the Pypy-commit
mailing list