fix(download): run burst2stack off a running event loop#144
Merged
scottstanie merged 1 commit intoMay 20, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BurstSearch.download()→burst2safe.burst2stack()→download_bursts()callsasyncio.run(). That raisesRuntimeError: asyncio.run() cannot be called from a running event loopwheneverdownload()runs inside a thread that already owns a running loop — i.e. any Jupyter/IPython kernel, includingjupyter execute. The cold-cache download path was therefore unusable from notebooks (it only "worked" whenexisting_safes()short-circuited pastdownload()).Fix
Add
_call_off_running_loop(): ifasyncio.get_running_loop()finds a running loop, runburst2stackin a one-shotThreadPoolExecutorworker (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/blackclean. Verified the notebook download path executes underjupyter execute.🤖 Generated with Claude Code