[pypy-svn] r45896 - pypy/branch/pypy-more-rtti-inprogress/module/thread
arigo at codespeak.net
arigo at codespeak.net
Tue Aug 21 16:19:53 CEST 2007
Author: arigo
Date: Tue Aug 21 16:19:52 2007
New Revision: 45896
Modified:
pypy/branch/pypy-more-rtti-inprogress/module/thread/__init__.py
pypy/branch/pypy-more-rtti-inprogress/module/thread/os_thread.py
Log:
Only set up the GIL the first time the app-level start_new_thread() is
called. This should be enough to remove the need for a prebuilt lock
object during translation.
Modified: pypy/branch/pypy-more-rtti-inprogress/module/thread/__init__.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/module/thread/__init__.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/module/thread/__init__.py Tue Aug 21 16:19:52 2007
@@ -19,20 +19,3 @@
'_local': 'os_local.getlocaltype(space)',
'_please_provide_import_lock': '(space.w_True)', # for imp.py
}
-
- def __init__(self, space, *args):
- "NOT_RPYTHON: patches space.threadlocals to use real threadlocals"
- from pypy.module.thread import gil
- MixedModule.__init__(self, space, *args)
- prev = space.threadlocals.getvalue()
- space.threadlocals = gil.GILThreadLocals()
- space.threadlocals.setvalue(prev)
- space.threadlocals.enter_thread(space) # setup the main thread
- # add the GIL-releasing callback as an action on the space
- space.pending_actions.append(gil.GILReleaseAction(space.threadlocals))
-
- def setup_after_space_initialization(self):
- # the import lock is in imp.py. Import it after the space is fully
- # initialized.
- from pypy.module.__builtin__.importing import importhook
- importhook(self.space, 'imp')
Modified: pypy/branch/pypy-more-rtti-inprogress/module/thread/os_thread.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/module/thread/os_thread.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/module/thread/os_thread.py Tue Aug 21 16:19:52 2007
@@ -49,6 +49,22 @@
e.clear(space)
+def setup_threads(space):
+ """Enable threads in the object space, if they haven't already been."""
+ from pypy.module.thread.gil import GILThreadLocals, GILReleaseAction
+ from pypy.module.__builtin__.importing import importhook
+ if not isinstance(space.threadlocals, GILThreadLocals):
+ # patches space.threadlocals to use real threadlocals
+ prev = space.threadlocals.getvalue()
+ space.threadlocals = GILThreadLocals()
+ space.threadlocals.setvalue(prev)
+ space.threadlocals.enter_thread(space) # setup the main thread
+ # add the GIL-releasing callback as an action on the space
+ space.pending_actions.append(GILReleaseAction(space.threadlocals))
+ # the import lock is in imp.py, which registers a custom import
+ # hook with this lock.
+ importhook(space, 'imp')
+
def start_new_thread(space, w_callable, w_args, w_kwargs=NoneNotWrapped):
"""Start a new thread and return its identifier. The thread will call the
function with positional arguments from the tuple args and keyword arguments
@@ -56,6 +72,7 @@
function returns; the return value is ignored. The thread will also exit
when the function raises an unhandled exception; a stack trace will be
printed unless the exception is SystemExit."""
+ setup_threads(space)
if not space.is_true(space.isinstance(w_args, space.w_tuple)):
raise OperationError(space.w_TypeError,
space.wrap("2nd arg must be a tuple"))
More information about the Pypy-commit
mailing list