Skip to content

Commit 5b4f173

Browse files
committed
Removed ipykernel stack frames from the callstack
1 parent 0181d70 commit 5b4f173

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ipykernel/debugger.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,17 @@ async def source(self, message):
302302

303303
async def stackTrace(self, message):
304304
reply = await self._forward_message(message)
305-
reply['body']['stackFrames'] = \
306-
[frame for frame in reply['body']['stackFrames'] if frame['source']['path'] != '<string>']
305+
# We stackFrames array has the following content:
306+
# { frames from the notebook}
307+
# ...
308+
# { 'id': xxx, 'name': '<module>', ... } <= this is the first frame of the code from the notebook
309+
# { frame from ipykernel }
310+
# ...
311+
# {'id': yyy, 'name': '<module>', ... } <= this is the first frame of ipykernel code
312+
# We want to remove all the frames from ipykernel
313+
sf_list = reply['body']['stackFrames']
314+
module_idx = len(sf_list) - next(i for i, v in enumerate(reversed(sf_list), 1) if v['name'] == '<module>' and i != 1)
315+
reply['body']['stackFrames'] = reply['body']['stackFrames'][:module_idx+1]
307316
return reply
308317

309318
def accept_variable(self, variable):

0 commit comments

Comments
 (0)