OSDN Git Service

Restart automatically if NVDA crashes.
authorJames Teh <jamie@jantrid.net>
Tue, 9 Aug 2011 00:32:15 +0000 (10:32 +1000)
committerJames Teh <jamie@jantrid.net>
Tue, 9 Aug 2011 00:32:15 +0000 (10:32 +1000)
source/watchdog.py
user_docs/en/changes.t2t

index be0b179..fc0534f 100644 (file)
@@ -2,7 +2,8 @@ import sys
 import traceback\r
 import time\r
 import threading\r
-from ctypes import *\r
+from ctypes import windll, oledll\r
+import ctypes.wintypes\r
 import winUser\r
 from logHandler import log\r
 \r
@@ -102,6 +103,15 @@ def _recoverAttempt():
        except:\r
                pass\r
 \r
+@ctypes.WINFUNCTYPE(ctypes.wintypes.LONG, ctypes.c_void_p)\r
+def crashHandler(exceptionInfo):\r
+       # An exception might have been set for this thread.\r
+       # Clear it so that it doesn't get raised in this function.\r
+       ctypes.pythonapi.PyThreadState_SetAsyncExc(threading.currentThread().ident, None)\r
+       import core\r
+       core.restart()\r
+       return 1 # EXCEPTION_EXECUTE_HANDLER\r
+\r
 def initialize():\r
        """Initialize the watchdog.\r
        """\r
@@ -109,6 +119,8 @@ def initialize():
        if isRunning:\r
                raise RuntimeError("already running") \r
        isRunning=True\r
+       # Catch application crashes.\r
+       windll.kernel32.SetUnhandledExceptionFilter(crashHandler)\r
        oledll.ole32.CoEnableCallCancellation(None)\r
        _coreAliveEvent.set()\r
        _resumeEvent.set()\r
index 9f6b77d..d1e34a4 100644 (file)
@@ -9,6 +9,7 @@
 - In Mozilla Gecko (e.g. Firefox) Heading levels are now announced  when using object navigation.\r
 - Text formatting can now be reported when using browse mode in Mozilla Gecko (e.g. Firefox and Thunderbird). (#394)\r
 - Text with underline and/or strikethrough can now be detected and reported in standard IAccessible2 text controls such as in Mozilla applications.\r
+- NVDA will now restart itself if it crashes.\r
 \r
 \r
 == Bug Fixes ==\r