File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,13 @@ def __init__(self, address: str) -> None:
59
59
self .address = address
60
60
self .model = redis .from_url (self .address )
61
61
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 ()
67
+
68
+ asyncio .set_event_loop (self .loop )
63
69
64
70
def store (self , key : str , item : str = "value" ) -> None :
65
71
"""Store a key value pair in the provided redis server.
Original file line number Diff line number Diff line change @@ -199,7 +199,15 @@ def usgs_earthquake_data(
199
199
200
200
click .echo ("Post mode enabled: Sending data..." )
201
201
click .echo (f"Querying redis at { backpack_dispatcher .redis .address } " )
202
- loop = asyncio .new_event_loop ()
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
+ asyncio .set_event_loop (loop )
210
+
203
211
loop .run_until_complete (backpack_dispatcher .direct_connect ())
204
212
205
213
click .echo ("complete" )
You can’t perform that action at this time.
0 commit comments