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

Client: attempt to switch to synchronous mode when existing event loop is detected #1940

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions optimade/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@
A mapping from base URL to `QueryResults` for each queried API.

"""

if self.use_async:
# Check for a pre-existing event loop (e.g. within a Jupyter notebook)
# and use it if present
Expand All @@ -680,9 +679,10 @@
"Detected a running event loop, cannot run in async mode."
)
self._progress.print(
"Detected a running event loop (e.g., Jupyter, pytest). Trying to use nest_asyncio."
"Detected a running event loop (e.g., Jupyter). Attempting to switch to synchronous mode."
)
self.use_async = False
self._http_client = requests.Session

Check warning on line 685 in optimade/client/client.py

View check run for this annotation

Codecov / codecov/patch

optimade/client/client.py#L685

Added line #L685 was not covered by tests
except RuntimeError:
event_loop = None

Expand Down