[pypy-svn] pypy interplevel-exception-classes: rewrite thread.error at interp-level and get rid of app_thread.py

amauryfa commits-noreply at bitbucket.org
Fri Feb 18 11:49:23 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: interplevel-exception-classes
Changeset: r42145:5ce5fe1cf557
Date: 2011-02-18 11:48 +0100
http://bitbucket.org/pypy/pypy/changeset/5ce5fe1cf557/

Log:	rewrite thread.error at interp-level and get rid of app_thread.py

diff --git a/pypy/module/thread/__init__.py b/pypy/module/thread/__init__.py
--- a/pypy/module/thread/__init__.py
+++ b/pypy/module/thread/__init__.py
@@ -4,7 +4,6 @@
 
 class Module(MixedModule):
     appleveldefs = {
-        'error':                  'app_thread.error',
     }
 
     interpleveldefs = {
@@ -19,6 +18,7 @@
         'allocate':               'os_lock.allocate_lock',  # obsolete synonym
         'LockType':               'os_lock.getlocktype(space)',
         '_local':                 'os_local.getlocaltype(space)',
+        'error':                  'space.fromcache(error.Cache).w_error',
     }
 
     def __init__(self, space, *args):

diff --git a/pypy/module/thread/app_thread.py b/pypy/module/thread/app_thread.py
deleted file mode 100644
--- a/pypy/module/thread/app_thread.py
+++ /dev/null
@@ -1,2 +0,0 @@
-class error(Exception):
-    pass

diff --git a/pypy/module/thread/test/test_fork.py b/pypy/module/thread/test/test_fork.py
--- a/pypy/module/thread/test/test_fork.py
+++ b/pypy/module/thread/test/test_fork.py
@@ -41,6 +41,9 @@
         "Checks that a forked interpreter can start a thread"
         import os, thread, time
 
+        if not hasattr(os, 'fork'):
+            skip("No fork on this platform")
+
         # pre-allocate some locks
         thread.start_new_thread(lambda: None, ())
 

diff --git a/pypy/module/thread/error.py b/pypy/module/thread/error.py
--- a/pypy/module/thread/error.py
+++ b/pypy/module/thread/error.py
@@ -1,6 +1,9 @@
 from pypy.interpreter.error import OperationError
 
+class Cache:
+    def __init__(self, space):
+        self.w_error = space.new_exception_class("thread.error")
+
 def wrap_thread_error(space, msg):
-    w_module = space.getbuiltinmodule('thread')
-    w_error = space.getattr(w_module, space.wrap('error'))
+    w_error = space.fromcache(Cache).w_error
     return OperationError(w_error, space.wrap(msg))

diff --git a/pypy/module/thread/test/test_gil.py b/pypy/module/thread/test/test_gil.py
--- a/pypy/module/thread/test/test_gil.py
+++ b/pypy/module/thread/test/test_gil.py
@@ -22,7 +22,7 @@
         return True
     def getexecutioncontext(self):
         return FakeEC()
-    def getbuiltinmodule(self, name):
+    def fromcache(self, key):
         raise NotImplementedError
 
 


More information about the Pypy-commit mailing list