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

Kernel crashes after setting decimal precision #1259

Closed
JasonWeill opened this issue Jul 26, 2024 · 3 comments · Fixed by jupyter/jupyter_client#1032
Closed

Kernel crashes after setting decimal precision #1259

JasonWeill opened this issue Jul 26, 2024 · 3 comments · Fixed by jupyter/jupyter_client#1032

Comments

@JasonWeill
Copy link

Originally reported by @eendebakpt in jupyterlab/jupyterlab#16268, and clarified by @williamstein on the same issue.

Using JupyterLab 4.3.0 alpha or Jupyter Console 6.6.3, with IPyKernel 6.29.5, run this cell:

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

… which should print first cell. Then, run the second cell:

print('second cell')

At this point, the following message appears, and the kernel becomes unresponsive:

[IPKernelApp] ERROR | Invalid Message
Traceback (most recent call last):
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/ipykernel/kernelbase.py", line 395, in dispatch_shell
    msg = self.session.deserialize(msg, content=True, copy=False)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/jupyter_client/session.py", line 1079, in deserialize
    message["header"] = extract_dates(header)
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/jupyter_client/jsonutil.py", line 75, in extract_dates
    new_obj[k] = extract_dates(v)
                 ^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/jupyter_client/jsonutil.py", line 80, in extract_dates
    obj = parse_date(obj)
          ^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/jupyter_client/jsonutil.py", line 65, in parse_date
    dt = _dateutil_parse(s)
         ^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 640, in parse
    res, skipped_tokens = self._parse(timestr, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 740, in _parse
    i = self._parse_numeric_token(l, i, info, ymd, res, fuzzy)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 942, in _parse_numeric_token
    (res.minute, res.second) = self._parse_min_sec(value)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 1106, in _parse_min_sec
    sec_remainder = value % 1
                    ~~~~~~^~~
decimal.InvalidOperation: [<class 'decimal.DivisionImpossible'>]
/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/jupyter_console/ptshell.py:787: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
  warn('The kernel did not respond to an is_complete_request. '
In [3]: print('second cell')
[IPKernelApp] ERROR | Invalid Message
Traceback (most recent call last):
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/ipykernel/kernelbase.py", line 395, in dispatch_shell
    msg = self.session.deserialize(msg, content=True, copy=False)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/jupyter_client/session.py", line 1079, in deserialize
    message["header"] = extract_dates(header)
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/jupyter_client/jsonutil.py", line 75, in extract_dates
    new_obj[k] = extract_dates(v)
                 ^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/jupyter_client/jsonutil.py", line 80, in extract_dates
    obj = parse_date(obj)
          ^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/jupyter_client/jsonutil.py", line 65, in parse_date
    dt = _dateutil_parse(s)
         ^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 640, in parse
    res, skipped_tokens = self._parse(timestr, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 740, in _parse
    i = self._parse_numeric_token(l, i, info, ymd, res, fuzzy)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 942, in _parse_numeric_token
    (res.minute, res.second) = self._parse_min_sec(value)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/jupyterlab-20240325/lib/python3.12/site-packages/dateutil/parser/_parser.py", line 1106, in _parse_min_sec
    sec_remainder = value % 1
                    ~~~~~~^~~
decimal.InvalidOperation: [<class 'decimal.DivisionImpossible'>]

I can reproduce this on macOS 13.6.7 (22G720) on Apple Silicon. Output of jupyter --version:

Selected Jupyter core packages...
IPython          : 8.24.0
ipykernel        : 6.29.5
ipywidgets       : 8.1.2
jupyter_client   : 8.6.1
jupyter_core     : 5.7.2
jupyter_server   : 2.14.0
jupyterlab       : 4.3.0a2
nbclient         : 0.10.0
nbconvert        : 7.16.4
nbformat         : 5.10.3
notebook         : not installed
qtconsole        : not installed
traitlets        : 5.14.3
@minrk
Copy link
Member

minrk commented Aug 8, 2024

Perhaps this should be reported to dateutil? Or Python itself?

A simple reproducer script without IPython at all:

import decimal
from datetime import datetime
from dateutil.parser import parse as parse_date

parse_date(datetime.now().isoformat())  # ok
con = decimal.getcontext()
con.prec = 1
parse_date(datetime.now().isoformat())  # error

@minrk
Copy link
Member

minrk commented Aug 8, 2024

Already reported in dateutil: dateutil/dateutil#1366

@minrk
Copy link
Member

minrk commented Aug 8, 2024

I believe this is fixed by jupyter/jupyter_client#1032

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.

2 participants