Skip to content

Commit dbbd1e5

Browse files
committed
Asyncio fixes
1 parent 6eb2d32 commit dbbd1e5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/sasquatchbackpack/sasquatch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ def __init__(self, address: str) -> None:
5959
self.address = address
6060
self.model = redis.from_url(self.address)
6161

62-
self.loop = asyncio.new_event_loop()
62+
# Get Existing loop, create one if it doesn't exist
63+
try:
64+
self.loop = asyncio.get_running_loop()
65+
except RuntimeError:
66+
self.loop = asyncio.new_event_loop()
6367

6468
def store(self, key: str, item: str = "value") -> None:
6569
"""Store a key value pair in the provided redis server.

src/sasquatchbackpack/sources/usgs/commands.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ def usgs_earthquake_data(
199199

200200
click.echo("Post mode enabled: Sending data...")
201201
click.echo(f"Querying redis at {backpack_dispatcher.redis.address}")
202-
asyncio.run(backpack_dispatcher.direct_connect())
202+
203+
# Get Existing loop, create one if it doesn't exist
204+
try:
205+
loop = asyncio.get_running_loop()
206+
except RuntimeError:
207+
loop = asyncio.new_event_loop()
208+
209+
loop.run_until_complete(backpack_dispatcher.direct_connect())
203210

204211
click.echo("complete")
205212

0 commit comments

Comments
 (0)