Skip to content

Commit

Permalink
refactor: execute in a separate thread (#110)
Browse files Browse the repository at this point in the history
Just running async was still blocking the WebUI while a generation was running.
  • Loading branch information
Maeyanie authored May 21, 2024
1 parent 21cdca4 commit 5b02b24
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from fastapi import FastAPI
import gradio as gr
from gradio.utils import run_coro_in_background
import asyncio
import requests
from threading import Thread

from modules import scripts, script_callbacks, sd_models, shared

Expand All @@ -15,16 +16,15 @@


def on_app_started(demo: Optional[gr.Blocks], app: FastAPI):
import asyncio

started = False

@app.on_event("startup")
@app.get("/horde/startup-events")
async def startup_event():
nonlocal started
if not started:
run_coro_in_background(horde.run)
thread = Thread(daemon=True, target=horde_thread)
thread.start()
started = True

# This is a hack to make sure the startup event is
Expand All @@ -38,6 +38,10 @@ async def startup_event():
requests.get(f"{local_url}horde/startup-events")


def horde_thread():
asyncio.run(horde.run())


def apply_stable_horde_settings(
enable: bool,
name: str,
Expand Down

0 comments on commit 5b02b24

Please sign in to comment.