mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-10-13 23:37:16 +08:00
Use existing send sync method
This commit is contained in:
parent
4f976f6080
commit
07271b27a7
@ -1,4 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
from app.logger import on_flush
|
from app.logger import on_flush
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -9,7 +8,7 @@ class TerminalService:
|
|||||||
self.cols = None
|
self.cols = None
|
||||||
self.rows = None
|
self.rows = None
|
||||||
self.subscriptions = set()
|
self.subscriptions = set()
|
||||||
on_flush(self.send_messages_sync)
|
on_flush(self.send_messages)
|
||||||
|
|
||||||
def update_size(self):
|
def update_size(self):
|
||||||
sz = os.get_terminal_size()
|
sz = os.get_terminal_size()
|
||||||
@ -33,24 +32,10 @@ class TerminalService:
|
|||||||
def unsubscribe(self, client_id):
|
def unsubscribe(self, client_id):
|
||||||
self.subscriptions.discard(client_id)
|
self.subscriptions.discard(client_id)
|
||||||
|
|
||||||
def send_messages_sync(self, entries):
|
def send_messages(self, entries):
|
||||||
if not len(entries) or not len(self.subscriptions):
|
if not len(entries) or not len(self.subscriptions):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
|
||||||
loop = asyncio.get_running_loop()
|
|
||||||
except RuntimeError:
|
|
||||||
loop = None
|
|
||||||
|
|
||||||
if loop and loop.is_running():
|
|
||||||
loop.create_task(self.send_messages(entries))
|
|
||||||
else:
|
|
||||||
asyncio.run(self.send_messages(entries))
|
|
||||||
|
|
||||||
async def send_messages(self, entries):
|
|
||||||
if not len(entries):
|
|
||||||
return
|
|
||||||
|
|
||||||
new_size = self.update_size()
|
new_size = self.update_size()
|
||||||
|
|
||||||
for client_id in self.subscriptions:
|
for client_id in self.subscriptions:
|
||||||
@ -59,5 +44,4 @@ class TerminalService:
|
|||||||
self.unsubscribe(client_id)
|
self.unsubscribe(client_id)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
await self.server.send_json(
|
self.server.send_sync("logs", {"entries": entries, "size": new_size}, client_id)
|
||||||
"logs", {"entries": entries, "size": new_size}, client_id)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user