Skip to content

Commit

Permalink
Merge pull request freqtrade#5530 from freqtrade/fix_uvicorn
Browse files Browse the repository at this point in the history
Fix uvicorn not working properly on windows
  • Loading branch information
xmatthias authored Sep 4, 2021
2 parents 35267de + 493fb35 commit 63f2494
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion freqtrade/rpc/api_server/uvicorn_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
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):
"""
Multithreaded server - as found in https://github.com/encode/uvicorn/issues/742
Expand All @@ -28,7 +42,7 @@ def run(self, sockets=None):
try:
import uvloop # noqa
except ImportError: # pragma: no cover
from uvicorn.loops.asyncio import asyncio_setup

asyncio_setup()
else:
asyncio.set_event_loop(uvloop.new_event_loop())
Expand Down

0 comments on commit 63f2494

Please sign in to comment.