fix: fix Jupyter event loop conflict - #1357
Merged
laurencap merged 3 commits intoSep 28, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1357 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 171 171
Lines 11648 11667 +19
Branches 1538 1539 +1
=========================================
+ Hits 11648 11667 +19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
laurencap
force-pushed
the
fix/issue-857-event-loop-conflict
branch
from
September 25, 2026 20:12
4f73f73 to
c5ba929
Compare
rmshaffer
approved these changes
Sep 28, 2026
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.
fix: avoid nested event loop in AwsQuantumTask.result() in Jupyter
Issue #, if available:
Fixes amazon-braket/amazon-braket-examples#857
Written with Kiro Opus 5.5.
Description of changes:
Bug: Calling
AwsQuantumTask.result()from a thread with a running event loop (e.g. a Jupyter cell) nestedrun_until_complete()on that loop vianest_asyncio. On Python 3.12 this logs"RuntimeError: cannot enter context: ... is already entered" from Task.__step, even though the result is returned.New: When a loop is already running,
result()now polls on a worker thread with its own event loop viaasyncio.run()instead of nesting. Interrupting the kernel (e.g. from jupyter) will cancel the polling loop._get_future()creates the polling task withloop.create_task(), which removes the need for_create_future()and fixes the issue in the case where the customer callsawait task.async_result().Follow up work: we no longer need
nest_asyncio.Testing done:
I was able to reliably reproduce the error by running this example notebook: https://github.com/amazon-braket/amazon-braket-examples/blob/main/examples/braket_features/Allocating_Qubits_on_QPU_Devices.ipynb
With these changes, the issue no longer appears.
Added new unit tests.
Merge Checklist
General
Tests
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.