Commits

Brian Kearns committed 46b7094

wrap the exception in signals_exit

  • Participants
  • Parent commits 06d1093

Comments (0)

Files changed (4)

File pypy/interpreter/miscutils.py

     def signals_enabled(self):
         return True
 
-    def enable_signals(self):
+    def enable_signals(self, space):
         pass
 
-    def disable_signals(self):
+    def disable_signals(self, space):
         pass
 
     def getallvalues(self):

File pypy/module/__pypy__/interp_signal.py

 
 def signals_enter(space):
-    space.threadlocals.enable_signals()
+    space.threadlocals.enable_signals(space)
 
 def signals_exit(space, w_ignored1=None, w_ignored2=None, w_ignored3=None):
-    space.threadlocals.disable_signals()
+    space.threadlocals.disable_signals(space)

File pypy/module/__pypy__/test/test_signal.py

 from pypy.module.thread.test.support import GenericTestThread
 
 
-class TestThreadSignal:
-    spaceconfig = dict(usemodules=['__pypy__', 'thread'])
-
-    def test_exit_twice(self, space):
-        from pypy.module.__pypy__.interp_signal import signals_exit, signals_enter
-        signals_exit(space)
-        try:
-            raises(KeyError, signals_exit, space)
-        finally:
-            signals_enter(space)
-
-
 class AppTestMinimal:
     spaceconfig = dict(usemodules=['__pypy__'])
 
 class AppTestThreadSignal(GenericTestThread):
     spaceconfig = dict(usemodules=['__pypy__', 'thread', 'signal', 'time'])
 
+    def test_exit_twice(self):
+        from __pypy__ import thread
+        thread._signals_exit()
+        try:
+            raises(KeyError, thread._signals_exit)
+        finally:
+            thread._signals_enter()
+
     def test_enable_signals(self):
         import __pypy__, thread, signal, time
 

File pypy/module/thread/threadlocals.py

 from rpython.rlib import rthread
+from pypy.interpreter.error import OperationError
 
 
 class OSThreadLocals:
     def signals_enabled(self):
         return rthread.get_ident() in self._signalsenabled
 
-    def enable_signals(self):
+    def enable_signals(self, space):
         ident = rthread.get_ident()
         old = self._signalsenabled.get(ident, 0)
         self._signalsenabled[ident] = old + 1
 
-    def disable_signals(self):
+    def disable_signals(self, space):
         ident = rthread.get_ident()
-        new = self._signalsenabled[ident] - 1
+        try:
+            new = self._signalsenabled[ident] - 1
+        except KeyError:
+            raise OperationError(space.w_KeyError, space.wrap(
+                "cannot disable signals in thread not enabled for signals"))
         if new > 0:
             self._signalsenabled[ident] = new
         else: