-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
50 lines (38 loc) · 1.61 KB
/
server.py
File metadata and controls
50 lines (38 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Minimal PromptServer stub — replaces the aiohttp-based server.
Provides just enough interface for PromptExecutor and PromptQueue.
"""
import asyncio
import logging
import execution
from app.node_replace_manager import NodeReplaceManager
class PromptServer:
instance = None
def __init__(self, loop: asyncio.AbstractEventLoop):
PromptServer.instance = self
self.loop = loop
self.client_id = None
self.last_prompt_id = None
self.last_node_id = None
self.sockets_metadata: dict = {}
self.number = 0
self.pending_sdapi: dict = {}
self.node_replace_manager = NodeReplaceManager()
self.prompt_queue = execution.PromptQueue(self)
self.prompt_queue.add_task_done_callback(self._sdapi_task_done_callback)
# ------------------------------------------------------------------ #
# Interface expected by PromptExecutor / PromptQueue / custom nodes #
# ------------------------------------------------------------------ #
def send_sync(self, event, data, sid=None):
pass # no WebSocket clients
def queue_updated(self):
pass
def send_progress_text(self, text, node_id, sid=None):
pass
# ------------------------------------------------------------------ #
# SDAPI completion signalling #
# ------------------------------------------------------------------ #
def _sdapi_task_done_callback(self, prompt_id: str):
event = self.pending_sdapi.get(prompt_id)
if event is not None:
self.loop.call_soon_threadsafe(event.set)