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

AssertionError: assert 0 < size <= self._size in tornado/iostream.py when displaying a large image before other images #6933

Closed
kerrickstaley opened this issue Jun 18, 2023 · 1 comment
Labels
bug status:Needs Triage Applied to issues that need triage

Comments

@kerrickstaley
Copy link

Summary

When I try to display a large-ish image (800x800 JPEG) using the Pillow Python library in Jupyter Notebook before displaying any smaller images in the notebook, the notebook hangs. In the terminal, I see this error message:

[E 11:01:18.952 NotebookApp] Uncaught exception, closing connection.
    Traceback (most recent call last):
      File "/Users/kerrick/Library/Python/3.11/lib/python/site-packages/tornado/iostream.py", line 702, in _handle_events
        self._handle_write()
      File "/Users/kerrick/Library/Python/3.11/lib/python/site-packages/tornado/iostream.py", line 976, in _handle_write
        self._write_buffer.advance(num_bytes)
      File "/Users/kerrick/Library/Python/3.11/lib/python/site-packages/tornado/iostream.py", line 182, in advance
        assert 0 < size <= self._size
               ^^^^^^^^^^^^^^^^^^^^^^
    AssertionError
Exception in callback None()
handle: <Handle cancelled>
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/kerrick/Library/Python/3.11/lib/python/site-packages/tornado/platform/asyncio.py", line 206, in _handle_events
    handler_func(fileobj, events)
  File "/Users/kerrick/Library/Python/3.11/lib/python/site-packages/tornado/iostream.py", line 702, in _handle_events
    self._handle_write()
  File "/Users/kerrick/Library/Python/3.11/lib/python/site-packages/tornado/iostream.py", line 976, in _handle_write
    self._write_buffer.advance(num_bytes)
  File "/Users/kerrick/Library/Python/3.11/lib/python/site-packages/tornado/iostream.py", line 182, in advance
    assert 0 < size <= self._size
           ^^^^^^^^^^^^^^^^^^^^^^
AssertionError

This doesn't always happen consistently. Sometimes the image displays successfully the first time but then I get the crash when I re-run the cell. Other times it displays halfway and cuts off in the middle.

A 600x600 rescale of the same image does not crash the notebook. Also, interestingly, if I display the 600x600 image first and then display the 800x800 image in a later cell, it does not crash.

After this happens the notebook is unresponsive and I can't seem to restart the notebook kernel from the UI; the only recourse is to Ctrl+C the python3 -m jupyter notebook process from the terminal.

To reproduce

  1. Download crash_800x800.jpg and no_crash_600x600.jpg from this Google Drive folder. (Try clicking "Download all" if the normal "Download" link doesn't work; Google seems to have a bug).
  2. Install the Pillow Python library.
  3. Run this code in a notebook. Maybe re-run the cell a couple times:
from PIL import Image
Image.open('crash_800x800.jpg')

Expected behavior

The image displays.

Actual behavior

I get a crash with the above-mentioned error message.

Version information

OS: macOS 13.3.1 (a) (22E772610a) on MacBook Air M2
Jupyter Version: 6.5.4-2c95aa495
Jupyter Python version: Python 3.11.4 (main, Jun 7 2023, 00:34:59) [Clang 14.0.3 (clang-1403.0.22.14.1)]
Jupyter Kernel:

Python 3.11.4 (main, Jun  7 2023, 00:34:59) [Clang 14.0.3 (clang-1403.0.22.14.1)]
IPython 8.12.0

Browser: Chrome 112.0.5615.137 (Official Build) (arm64)

Notes:

If you instead use no_crash_600x600.jpg, the crash will not trigger.

Also, if you run these two cells in order:

from PIL import Image
Image.open('no_crash_600x600.jpg')
Image.open('crash_800x800.jpg')

then you can re-run the second cell repeatedly and it will not crash.

@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to issues that need triage label Jun 18, 2023
@RRosio
Copy link
Collaborator

RRosio commented Jun 20, 2023

Hi @kerrickstaley thank you for submitting this issue. This is a known bug that has been reported in #6721. Closing this issue as a duplicate of that one.

@RRosio RRosio closed this as completed Jun 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug status:Needs Triage Applied to issues that need triage
Projects
None yet
Development

No branches or pull requests

2 participants