stable/freqtrade/rpc/api_server2/uvicorn_threaded.py

29 lines
662 B
Python

import contextlib
import time
import threading
import uvicorn
class UvicornServer(uvicorn.Server):
"""
Multithreaded server - as found in https://github.com/encode/uvicorn/issues/742
"""
def install_signal_handlers(self):
pass
@contextlib.contextmanager
def run_in_thread(self):
self.thread = threading.Thread(target=self.run)
self.thread.start()
# try:
while not self.started:
time.sleep(1e-3)
# yield
# finally:
# self.should_exit = True
# thread.join()
def cleanup(self):
self.should_exit = True
self.thread.join()