Merge pull request #5530 from freqtrade/fix_uvicorn

Fix uvicorn not working properly on windows
This commit is contained in:
Matthias 2021-09-04 08:22:11 +02:00 committed by GitHub
commit 63f2494936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,20 @@ import time
import uvicorn import uvicorn
def asyncio_setup() -> None: # pragma: no cover
# Set eventloop for win32 setups
# Reverts a change done in uvicorn 0.15.0 - which now sets the eventloop
# via policy.
import sys
if sys.version_info >= (3, 8) and sys.platform == "win32":
import asyncio
import selectors
selector = selectors.SelectSelector()
loop = asyncio.SelectorEventLoop(selector)
asyncio.set_event_loop(loop)
class UvicornServer(uvicorn.Server): class UvicornServer(uvicorn.Server):
""" """
Multithreaded server - as found in https://github.com/encode/uvicorn/issues/742 Multithreaded server - as found in https://github.com/encode/uvicorn/issues/742
@ -28,7 +42,7 @@ class UvicornServer(uvicorn.Server):
try: try:
import uvloop # noqa import uvloop # noqa
except ImportError: # pragma: no cover except ImportError: # pragma: no cover
from uvicorn.loops.asyncio import asyncio_setup
asyncio_setup() asyncio_setup()
else: else:
asyncio.set_event_loop(uvloop.new_event_loop()) asyncio.set_event_loop(uvloop.new_event_loop())