From b949ea301c5828612f094c1c5040a67adcd3a47e Mon Sep 17 00:00:00 2001 From: Timothy Pogue Date: Mon, 5 Sep 2022 19:29:07 -0600 Subject: [PATCH] fix failed apiserver tests --- freqtrade/rpc/api_server/webserver.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/freqtrade/rpc/api_server/webserver.py b/freqtrade/rpc/api_server/webserver.py index ad93e77a7..6ad3f143e 100644 --- a/freqtrade/rpc/api_server/webserver.py +++ b/freqtrade/rpc/api_server/webserver.py @@ -114,6 +114,10 @@ class ApiServer(RPCHandler): self._thread.join() + self._thread = None + self._loop = None + self._background_task = None + @classmethod def shutdown(cls): cls.__initialized = False @@ -169,15 +173,15 @@ class ApiServer(RPCHandler): app.add_exception_handler(RPCException, self.handle_rpc_exception) def start_message_queue(self): + if self._thread: + return + # Create a new loop, as it'll be just for the background thread self._loop = asyncio.new_event_loop() # Start the thread - if not self._thread: - self._thread = Thread(target=self._loop.run_forever) - self._thread.start() - else: - raise RuntimeError("Threaded loop is already running") + self._thread = Thread(target=self._loop.run_forever) + self._thread.start() # Finally, submit the coro to the thread self._background_task = asyncio.run_coroutine_threadsafe(