mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-01-19 21:00:14 +08:00
put asyncio fix into a function to make it more obvious where it starts and ends
This commit is contained in:
parent
24dec9c832
commit
86bafb625a
29
webui.py
29
webui.py
@ -5,7 +5,6 @@ import importlib
|
|||||||
import signal
|
import signal
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
import asyncio
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.middleware.gzip import GZipMiddleware
|
from fastapi.middleware.gzip import GZipMiddleware
|
||||||
@ -67,6 +66,19 @@ if cmd_opts.server_name:
|
|||||||
else:
|
else:
|
||||||
server_name = "0.0.0.0" if cmd_opts.listen else None
|
server_name = "0.0.0.0" if cmd_opts.listen else None
|
||||||
|
|
||||||
|
|
||||||
|
def fix_asyncio_event_loop_policy():
|
||||||
|
"""
|
||||||
|
The default `asyncio` event loop policy only automatically creates
|
||||||
|
event loops in the main threads. Other threads must create event
|
||||||
|
loops explicitly or `asyncio.get_event_loop` (and therefore
|
||||||
|
`.IOLoop.current`) will fail. Installing this policy allows event
|
||||||
|
loops to be created automatically on any thread, matching the
|
||||||
|
behavior of Tornado versions prior to 5.0 (or 5.0 on Python 2).
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"):
|
if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"):
|
||||||
# "Any thread" and "selector" should be orthogonal, but there's not a clean
|
# "Any thread" and "selector" should be orthogonal, but there's not a clean
|
||||||
# interface for composing policies so pick the right base.
|
# interface for composing policies so pick the right base.
|
||||||
@ -74,23 +86,11 @@ if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"
|
|||||||
else:
|
else:
|
||||||
_BasePolicy = asyncio.DefaultEventLoopPolicy
|
_BasePolicy = asyncio.DefaultEventLoopPolicy
|
||||||
|
|
||||||
|
|
||||||
class AnyThreadEventLoopPolicy(_BasePolicy): # type: ignore
|
class AnyThreadEventLoopPolicy(_BasePolicy): # type: ignore
|
||||||
"""Event loop policy that allows loop creation on any thread.
|
"""Event loop policy that allows loop creation on any thread.
|
||||||
|
|
||||||
The default `asyncio` event loop policy only automatically creates
|
|
||||||
event loops in the main threads. Other threads must create event
|
|
||||||
loops explicitly or `asyncio.get_event_loop` (and therefore
|
|
||||||
`.IOLoop.current`) will fail. Installing this policy allows event
|
|
||||||
loops to be created automatically on any thread, matching the
|
|
||||||
behavior of Tornado versions prior to 5.0 (or 5.0 on Python 2).
|
|
||||||
|
|
||||||
Usage::
|
Usage::
|
||||||
|
|
||||||
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
|
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
|
||||||
|
|
||||||
.. versionadded:: 5.0
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_event_loop(self) -> asyncio.AbstractEventLoop:
|
def get_event_loop(self) -> asyncio.AbstractEventLoop:
|
||||||
@ -104,7 +104,6 @@ class AnyThreadEventLoopPolicy(_BasePolicy): # type: ignore
|
|||||||
self.set_event_loop(loop)
|
self.set_event_loop(loop)
|
||||||
return loop
|
return loop
|
||||||
|
|
||||||
|
|
||||||
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
|
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
|
||||||
|
|
||||||
|
|
||||||
@ -140,6 +139,8 @@ Use --skip-version-check commandline argument to disable this check.
|
|||||||
|
|
||||||
|
|
||||||
def initialize():
|
def initialize():
|
||||||
|
fix_asyncio_event_loop_policy()
|
||||||
|
|
||||||
check_versions()
|
check_versions()
|
||||||
|
|
||||||
extensions.list_extensions()
|
extensions.list_extensions()
|
||||||
|
Loading…
Reference in New Issue
Block a user