You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f72bd37
Browse filesBrowse the repository at this point in the historyBrowse files
feat(helpers): add cef.UnraisableHook for exceptions escaping handlers
Cython 3 callback handlers are declared "noexcept", so an exception that
escapes a handler (one not wrapped in try/except, or whose except block
itself raises) does not propagate into CEF's C++ code. Python instead
reports it via sys.unraisablehook, which by default only prints to stderr
and is easy to miss.
Add a UnraisableHook helper, companion to ExceptHook, that forwards the
escaped exception to ExceptHook so it is written to error.log, printed,
and CEF is shut down cleanly - same as any other Python exception. Wire
it into the tutorial.py example (sys.unraisablehook = cef.UnraisableHook)
and document it in Tutorial.md and cefpython.md.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@@ -93,6 +94,9 @@ This hook does the following: in case of exception write it to
93
94
the "error.log" file, display it to the console, shutdown CEF
94
95
and exit application immediately by ignoring "finally" (_exit()).
95
96
97
+
See also [UnraisableHook](#unraisablehook) for exceptions that escape a
98
+
callback handler.
99
+
96
100
See also Tutorial: [Handling Python exceptions](../docs/Tutorial.md#handling-python-exceptions).
97
101
98
102
@@ -380,3 +384,31 @@ modal message loop. Set to false after exiting the modal message loop.
380
384
This function should be called on the main application thread (UI thread) to shut down CEF before the application exits.
381
385
382
386
You must call this function so that CEF shuts down cleanly. Remember also to delete all CEF browsers references for the browsers to shut down cleanly. For an example see the wxpython.py example MainFrame.OnClose().
387
+
388
+
389
+
### UnraisableHook
390
+
391
+
| Parameter | Type |
392
+
| --- | --- |
393
+
| unraisable | - |
394
+
|__Return__| void |
395
+
396
+
Global unraisable hook, companion to [ExceptHook](#excepthook). Assign it
397
+
with `sys.unraisablehook = cef.UnraisableHook`.
398
+
399
+
CEF Python's callback handlers are compiled with Cython and declared as
400
+
"noexcept", so an exception must not propagate out of a handler into CEF's
401
+
C++ code. Handlers catch their own exceptions and forward them to
402
+
`sys.excepthook`, but if an exception still escapes a handler (for example a
403
+
handler not wrapped in try/except, or whose except block itself raises) then
0 commit comments