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

Jupyter lab crashes when executing code with the python decimal module and precision 1 #16268

Closed
eendebakpt opened this issue Apr 30, 2024 · 7 comments · Fixed by jupyter/jupyter_client#1032
Labels

Comments

@eendebakpt
Copy link

Description

When importing the python builtin module decimal and setting the precision to 1 every second cell executed in jupyter lab freezes. The same code runs without problems in plain python.

Reproduce

Run the following code cells in Jupyter lab

image

The execution of the second cell fails, even though the code there is just a print statement.

On the console where jupyter lab was started is some output that might be helpful.

image

The same problem also occurs in Spyder. It seems related to the communication with the kernel that is running in the background.

Expected behavior

Even though the code itself might raise exceptions, jupyter lab should not freeze. The minimal example above might be a bit odd, but the more realistic case where the issue was encountered is not suitable for a minimal example.

Context

  • Operating System and version: Windows
  • Browser and version: Chrome
  • JupyterLab version: 4.1.4
Troubleshoot Output
Not available, jupyter lab freezes
Command Line Output
[IPKernelApp] ERROR | Invalid Message
Traceback (most recent call last):
  File "C:\develop\env312\Lib\site-packages\ipykernel\kernelbase.py", line 395, in dispatch_shell
    msg = self.session.deserialize(msg, content=True, copy=False)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\develop\env312\Lib\site-packages\jupyter_client\session.py", line 1082, in deserialize
    message["header"] = extract_dates(header)
                        ^^^^^^^^^^^^^^^^^^^^^
  File "C:\develop\env312\Lib\site-packages\jupyter_client\jsonutil.py", line 75, in extract_dates
    new_obj[k] = extract_dates(v)
                 ^^^^^^^^^^^^^^^^
  File "C:\develop\env312\Lib\site-packages\jupyter_client\jsonutil.py", line 80, in extract_dates
    obj = parse_date(obj)
          ^^^^^^^^^^^^^^^
  File "C:\develop\env312\Lib\site-packages\jupyter_client\jsonutil.py", line 65, in parse_date
    dt = _dateutil_parse(s)
         ^^^^^^^^^^^^^^^^^^
  File "C:\develop\env312\Lib\site-packages\dateutil\parser\_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\develop\env312\Lib\site-packages\dateutil\parser\_parser.py", line 640, in parse
    res, skipped_tokens = self._parse(timestr, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\develop\env312\Lib\site-packages\dateutil\parser\_parser.py", line 740, in _parse
    i = self._parse_numeric_token(l, i, info, ymd, res, fuzzy)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\develop\env312\Lib\site-packages\dateutil\parser\_parser.py", line 942, in _parse_numeric_token
    (res.minute, res.second) = self._parse_min_sec(value)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\develop\env312\Lib\site-packages\dateutil\parser\_parser.py", line 1106, in _parse_min_sec
    sec_remainder = value % 1
                    ~~~~~~^~~
decimal.InvalidOperation: []
Browser Output
-
@eendebakpt eendebakpt added the bug label Apr 30, 2024
Copy link

welcome bot commented Apr 30, 2024

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label Apr 30, 2024
@JasonWeill
Copy link
Contributor

I can reproduce this in a tip-of-main build (4.2.0rc0) on macOS Ventura 13.6.6 with Python 3.12.2.

@JasonWeill JasonWeill removed the status:Needs Triage Applied to new issues that need triage label May 1, 2024
@JasonWeill
Copy link
Contributor

I was unable to reproduce this in a terminal with IPython 8.22.2; this seems to be specific to JupyterLab. @eendebakpt Thank you for reporting this!

@williamstein
Copy link

this seems to be specific to JupyterLab

@JasonWeill can you try again? I was able to reproduce this in the terminal with IPython 8.26.0 and Jupyter console 6.6.3 by typing jupyter console --kernel=python3 and pasting in the code:

import decimal
d = decimal.Decimal('1001')
con = decimal.getcontext()
con.prec = 1
print('first cell')

then

print('second cell')
image

The Jupyter console is then totally unresponsive.

Also exactly the same failure happens in CoCalc, which shares no code with JupyterLab. This might be a problem in the implementation of ipykernel in Python, which has nothing to do with Jupyterlab or frontends.

I think it's misleading to say that "Jupyter lab crashes" in this case. It's more that the backend kernel crashes, and JupyterLab can't do anything further with it. I don't know what JupyterLab could do better in this case.

Context: I just went through and triaged all the CoCalc Jupyter issues, and decided to test whether some of the JupyterLab bugs were also CoCalc Jupyter bugs, and this was the first one I tried. It's nice that we have two very similar clients with distinct implementations.

Additional context: I remember having a long chat with Brian Granger at Scipy 2006 at Caltech about how kernels should work. In Sage we used pexpect and he wanted to use something different (eventually zmq), and my argument for pexpect was that you could always see any crashes, like in a terminal, whereas with zmq, if the kernel gets broke somehow, you might not be able to observe it, since the mechanism of observation itself breaks. Obviously overall zmq is much more efficient than pexpect, but this is the sort of issue I was concerned about.

@JasonWeill
Copy link
Contributor

@williamstein Thanks for clarifying! I was testing with IPython, but I hadn't had Jupyter Console installed. With Jupyter Console 6.6.3 and IPython 8.24.0 installed, I see the same error as in your screen shot above.

There is one IPyKernel issue that mentions decimal precision: ipython/ipykernel#494 — although it seems to be related to ipython/ipython#11565, which is closed, and which is not specific to the decimal package.

I see that ipython/ipykernel#1124 has the same "UserWarning: The kernel did not respond to an is_complete_request" message as in this issue. This was fixed in ipython/ipykernel#1237 , which was released in IPyKernel 6.29.5. I'm running 6.29.3.

@JasonWeill
Copy link
Contributor

After upgrading to ipykernel==6.29.5, I still see the error listed above.

I can open a new issue in https://github.com/ipython/ipykernel/issues and I'll block this issue on the new issue. Thanks again @williamstein !

@JasonWeill
Copy link
Contributor

Blocked on ipython/ipykernel#1259.

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

Successfully merging a pull request may close this issue.

3 participants