Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions binance/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ def get_loop():
inspired by https://stackoverflow.com/questions/46727787/runtimeerror-there-is-no-current-event-loop-in-thread-in-async-apscheduler
"""
try:
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
return loop
except RuntimeError as e:
if str(e).startswith("There is no current event loop in thread"):
if str(e).endswith("no running event loop"):

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message check is too narrow and may miss valid RuntimeError cases. The exact error message from asyncio.get_running_loop() is 'no running event loop', but this check only matches strings ending with this phrase. Consider using a more precise check like str(e) == 'no running event loop' or check for the specific exception type.

Suggested change
if str(e).endswith("no running event loop"):
if str(e) == "no running event loop":

Copilot uses AI. Check for mistakes.
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop
Expand Down
Loading