Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit efcb077

Browse files
authored
Update jupyter_app.py
1 parent a6b9adf commit efcb077

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

jupyter_dash/jupyter_app.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,32 @@
1717
from ansi2html import Ansi2HTMLConverter
1818
import uuid
1919

20+
from .comms import _dash_comm, _jupyter_config, _request_jupyter_config
2021

21-
from werkzeug.debug.tbtools import get_current_traceback
2222

23-
from .comms import _dash_comm, _jupyter_config, _request_jupyter_config
23+
def _get_skip(error: Exception, divider=2):
24+
25+
try:
26+
# pylint: disable=import-outside-toplevel
27+
from werkzeug.debug import tbtools
28+
except ImportError:
29+
tbtools = None
30+
31+
# werkzeug<2.1.0
32+
if hasattr(tbtools, "get_current_traceback"):
33+
tb = tbtools.get_current_traceback()
34+
text = tb.plaintext.splitlines()
35+
36+
if hasattr(tbtools, "DebugTraceback"):
37+
tb = tbtools.DebugTraceback(error) # pylint: disable=no-member
38+
text = tb.render_traceback_text().splitlines()
39+
40+
skip = 0
41+
for i, line in enumerate(text):
42+
if "%% callback invoked %%" in line:
43+
skip = int((i + 1) / divider)
44+
break
45+
return skip
2446

2547

2648
class JupyterDash(dash.Dash):
@@ -356,18 +378,12 @@ def _config_callback_exception_handling(
356378
):
357379

358380
@self.server.errorhandler(Exception)
359-
def _wrap_errors(_):
381+
def _wrap_errors(error):
360382
"""Install traceback handling for callbacks"""
361383
self._traceback = sys.exc_info()[2]
362384

363385
# Compute number of stack frames to skip to get down to callback
364-
tb_werkzeug = get_current_traceback()
365-
skip = 0
366-
if dev_tools_prune_errors:
367-
for i, line in enumerate(tb_werkzeug.plaintext.splitlines()):
368-
if "%% callback invoked %%" in line:
369-
skip = int((i + 1) / 2)
370-
break
386+
skip = _get_skip(error) if dev_tools_prune_errors else 0
371387

372388
# Customized formatargvalues function so we can place function parameters
373389
# on separate lines

0 commit comments

Comments
 (0)