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

Cannot interrupt async cell #2684

Open
davidbrochart opened this issue Oct 22, 2024 · 2 comments
Open

Cannot interrupt async cell #2684

davidbrochart opened this issue Oct 22, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@davidbrochart
Copy link

Describe the bug

The following code:

import asyncio

await asyncio.sleep(10)

cannot be interrupted: the cell runs until complete and then shows a CancelledError.

Environment

{
  "marimo": "0.9.11",
  "OS": "Linux",
  "OS Version": "6.8.0-47-generic",
  "Processor": "x86_64",
  "Python Version": "3.12.3",
  "Binaries": {
    "Browser": "130.0.6723.58",
    "Node": "v22.9.0"
  },
  "Dependencies": {
    "click": "8.1.3",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.1",
    "markdown": "3.7",
    "narwhals": "1.10.0",
    "packaging": "24.1",
    "psutil": "6.1.0",
    "pygments": "2.18.0",
    "pymdown-extensions": "10.11.2",
    "pyyaml": "6.0.2",
    "ruff": "0.6.9",
    "starlette": "0.41.0",
    "tomlkit": "0.13.2",
    "typing-extensions": "4.12.2",
    "uvicorn": "0.32.0",
    "websockets": "12.0"
  },
  "Optional Dependencies": {
    "duckdb": "1.1.2"
  }
}

Code to reproduce

import asyncio

await asyncio.sleep(10)
@davidbrochart davidbrochart added the bug Something isn't working label Oct 22, 2024
@akshayka
Copy link
Contributor

Thanks for the bug report. This is a known issue, but I'm not sure how to solve it. I believe ipykernel suffers from the same problem — actually I see you reported it there too :)

If you have

import asyncio

await asyncio.sleep(10)
print(1)

and interrupt the sleep, the cell doesn't actually run until complete — 1 won't be printed. But the sleep() can't be interrupted.

@akshayka
Copy link
Contributor

akshayka commented Oct 31, 2024

Actually, I think I know how to fix this, by adding the interrupt handler to the event loop when a coroutine is being awaited.

@akshayka akshayka self-assigned this Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants