Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v6 error with breakpoint in function #697

Closed
fcollonval opened this issue Jun 29, 2021 · 7 comments · Fixed by #702
Closed

v6 error with breakpoint in function #697

fcollonval opened this issue Jun 29, 2021 · 7 comments · Fixed by #702

Comments

@fcollonval
Copy link
Contributor

fcollonval commented Jun 29, 2021

The tested cell is:

def add(a, b):
    c = a + b
    return c

add(3, 2)

with the breakpoint set at c = a + b.

Demo of the error - it is only happening when listing the variables without debugging (aka kernel state):

bug_ipykernel

The error seen is:

[IPKernelApp] ERROR | Exception in control handler:
Traceback (most recent call last):
  File "/home/fcollonval/miniconda3/envs/jlab-dev/lib/python3.9/site-packages/ipykernel/kernelbase.py", line 280, in process_control
    await result
  File "/home/fcollonval/miniconda3/envs/jlab-dev/lib/python3.9/site-packages/ipykernel/kernelbase.py", line 832, in debug_request
    reply_content = json_clean(reply_content)
  File "/home/fcollonval/miniconda3/envs/jlab-dev/lib/python3.9/site-packages/ipykernel/jsonutil.py", line 142, in json_clean
    out[str(k)] = json_clean(v)
  File "/home/fcollonval/miniconda3/envs/jlab-dev/lib/python3.9/site-packages/ipykernel/jsonutil.py", line 142, in json_clean
    out[str(k)] = json_clean(v)
  File "/home/fcollonval/miniconda3/envs/jlab-dev/lib/python3.9/site-packages/ipykernel/jsonutil.py", line 128, in json_clean
    return [json_clean(x) for x in obj]
  File "/home/fcollonval/miniconda3/envs/jlab-dev/lib/python3.9/site-packages/ipykernel/jsonutil.py", line 128, in <listcomp>
    return [json_clean(x) for x in obj]
  File "/home/fcollonval/miniconda3/envs/jlab-dev/lib/python3.9/site-packages/ipykernel/jsonutil.py", line 142, in json_clean
    out[str(k)] = json_clean(v)
  File "/home/fcollonval/miniconda3/envs/jlab-dev/lib/python3.9/site-packages/ipykernel/jsonutil.py", line 148, in json_clean
    raise ValueError("Can't clean for JSON: %r" % obj)
ValueError: Can't clean for JSON: <function add at 0x7f1efa2198b0>

Xref: jupyterlab/jupyterlab#10502

@Carreau
Copy link
Member

Carreau commented Jun 29, 2021

I can't test right now, but can you try the following patch to narrow down the problem?

diff --git a/ipykernel/debugger.py b/ipykernel/debugger.py
index f3ea2a9..9e9c94c 100644
--- a/ipykernel/debugger.py
+++ b/ipykernel/debugger.py
@@ -456,12 +456,15 @@ class Debugger:
         handler = self.static_debug_handlers.get(message['command'], None)
         if handler is not None:
             reply = await handler(message)
+            assert isinstance(reply, dict), f"{handler=} {message=}"
         elif self.is_started:
             handler = self.started_debug_handlers.get(message['command'], None)
             if handler is not None:
                 reply = await handler(message)
+                assert isinstance(reply, dict), f"{handler=} {message=}"
             else:
                 reply = await self._forward_message(message)
+                assert isinstance(reply, dict), f"{message=}"

         if message['command'] == 'disconnect':
             self.stop()

@mlucool
Copy link
Contributor

mlucool commented Jun 29, 2021

This seems very similar to #647.

@Carreau
Copy link
Member

Carreau commented Jun 29, 2021

It seem indeed, I'll send a PRs the add some asserts, and improve some warnings and logging to narrow down where the issue comes from.

@fcollonval
Copy link
Contributor Author

The assertion are not raised.

When stop on the breakpoint, the function is indeed listed.

It looks like that the error comes from the following line as the value may not be jsonable:

'value': v,

This seems very similar to #647.

Indeed it seems that the pointer variable to functions (or class in the mentioned issue) are not returning a valid displayable description.

They may be other kind too.

@fcollonval
Copy link
Contributor Author

Changing that 422 line to

- 'value': v,
+ 'value': str(v),

results in no more error. But I guess the real patch should be more advanced than that.

@Carreau
Copy link
Member

Carreau commented Jun 30, 2021

Ah good catch. @JohanMabille I believe you wrote most of these and might be the most qualified to fix it.

@JohanMabille
Copy link
Contributor

I will work on this tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants