fix(client): make sync OEClient usable in Jupyter notebooks#32
Merged
Conversation
OEClient called asyncio.run() directly, which raises RuntimeError when a loop is already running — so the sync client failed in Jupyter/IPython notebooks. Route coroutines through _run_sync(), which falls back to a worker thread when a loop is already active. Fixes #16
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.
Closes #16
Problem
OEClient(sync) callsasyncio.run()internally.asyncio.run()raisesRuntimeError: asyncio.run() cannot be called from a running event loopwhen a loop is already running — which is always the case in a Jupyter/IPython notebook. So the synchronous client, the one notebook users reach for first, fails there.Fix
A
_run_sync()helper:asyncio.run()as beforeAll
OEClientmethods andclose()go through it. No API change, no new dependency (concurrent.futuresis stdlib).Verified
tests/test_run_sync.pycovers both paths (with and without a running loop).OEClient().get_facilities(...)called from insideasyncio.run(...)now succeeds (previouslyRuntimeError).