Skip to content

fix(download): run burst2stack off a running event loop#144

Merged
scottstanie merged 1 commit into
isce-framework:mainfrom
scottstanie:fix-notebook-asyncio-run
May 20, 2026
Merged

fix(download): run burst2stack off a running event loop#144
scottstanie merged 1 commit into
isce-framework:mainfrom
scottstanie:fix-notebook-asyncio-run

Conversation

@scottstanie
Copy link
Copy Markdown
Member

Problem

BurstSearch.download()burst2safe.burst2stack()download_bursts() calls asyncio.run(). That raises RuntimeError: asyncio.run() cannot be called from a running event loop whenever download() runs inside a thread that already owns a running loop — i.e. any Jupyter/IPython kernel, including jupyter execute. The cold-cache download path was therefore unusable from notebooks (it only "worked" when existing_safes() short-circuited past download()).

Fix

Add _call_off_running_loop(): if asyncio.get_running_loop() finds a running loop, run burst2stack in a one-shot ThreadPoolExecutor worker (fresh loop); otherwise call it directly. The plain script/CLI path is byte-for-byte unchanged (no extra thread).

This is a sweets-side workaround for burst2safe's asyncio.run(); an upstream loop-aware fix in burst2safe would be cleaner long-term but is independent of this.

Test

mypy/ruff/black clean. Verified the notebook download path executes under jupyter execute.

🤖 Generated with Claude Code

burst2safe downloads via asyncio.run(), which raises RuntimeError when
BurstSearch.download() is called from a thread that already owns a
running loop (Jupyter/IPython kernel, jupyter execute). Add a guard that
detects a running loop and runs burst2stack in a one-shot worker thread
so its asyncio.run() gets a fresh loop; the script/CLI path is unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@scottstanie scottstanie merged commit 0595cbf into isce-framework:main May 20, 2026
4 checks passed
@scottstanie scottstanie deleted the fix-notebook-asyncio-run branch May 20, 2026 14:07
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 this pull request may close these issues.

1 participant