From 37e3d20357943e18e0f0197a11e911aa4d2031e0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 17 Aug 2021 06:54:10 +0200 Subject: [PATCH] Fix no-event-loop available closes #5433 --- freqtrade/rpc/api_server/uvicorn_threaded.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/freqtrade/rpc/api_server/uvicorn_threaded.py b/freqtrade/rpc/api_server/uvicorn_threaded.py index 2f72cb74c..b63999f51 100644 --- a/freqtrade/rpc/api_server/uvicorn_threaded.py +++ b/freqtrade/rpc/api_server/uvicorn_threaded.py @@ -32,8 +32,11 @@ class UvicornServer(uvicorn.Server): asyncio_setup() else: asyncio.set_event_loop(uvloop.new_event_loop()) - - loop = asyncio.get_event_loop() + try: + loop = asyncio.get_event_loop() + except RuntimeError: + # When running in a thread, we'll not have an eventloop yet. + loop = asyncio.new_event_loop() loop.run_until_complete(self.serve(sockets=sockets)) @contextlib.contextmanager