jupyterlab
jupyterlab copied to clipboard
Jupyter lab crashes when executing code with the python decimal module and precision 1
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
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.
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
-
Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
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.
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! :wave:
Welcome to the Jupyter community! :tada:
I can reproduce this in a tip-of-main build (4.2.0rc0) on macOS Ventura 13.6.6 with Python 3.12.2.
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!
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')
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.
@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: https://github.com/ipython/ipykernel/issues/494 — although it seems to be related to https://github.com/ipython/ipython/issues/11565, which is closed, and which is not specific to the decimal package.
I see that https://github.com/ipython/ipykernel/issues/1124 has the same "UserWarning: The kernel did not respond to an is_complete_request" message as in this issue. This was fixed in https://github.com/ipython/ipykernel/pull/1237 , which was released in IPyKernel 6.29.5. I'm running 6.29.3.
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 !
Blocked on https://github.com/ipython/ipykernel/issues/1259.