Some checks failed
Python Linting / Run Ruff (push) Has been cancelled
Python Linting / Run Pylint (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Has been cancelled
Execution Tests / test (macos-latest) (push) Has been cancelled
Execution Tests / test (ubuntu-latest) (push) Has been cancelled
Execution Tests / test (windows-latest) (push) Has been cancelled
Test server launches without errors / test (push) Has been cancelled
Unit Tests / test (macos-latest) (push) Has been cancelled
Unit Tests / test (ubuntu-latest) (push) Has been cancelled
Unit Tests / test (windows-2022) (push) Has been cancelled
Includes 30 custom nodes committed directly, 7 Civitai-exclusive loras stored via Git LFS, and a setup script that installs all dependencies and downloads HuggingFace-hosted models on vast.ai. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
import asyncio
|
|
import server
|
|
import time
|
|
import threading
|
|
from .hardware import CHardwareInfo
|
|
|
|
from ..core import logger
|
|
|
|
lock = threading.Lock()
|
|
|
|
|
|
class CMonitor:
|
|
monitorThread = None
|
|
threadController = threading.Event()
|
|
rate = 0
|
|
hardwareInfo = None
|
|
|
|
def __init__(self, rate=5, switchCPU=False, switchGPU=False, switchHDD=False, switchRAM=False, switchVRAM=False):
|
|
self.rate = rate
|
|
self.hardwareInfo = CHardwareInfo(switchCPU, switchGPU, switchHDD, switchRAM, switchVRAM)
|
|
|
|
self.startMonitor()
|
|
|
|
async def send_message(self, data) -> None:
|
|
# I'm not sure if it is ok, but works ¯\_(ツ)_/¯
|
|
# I tried to use async with send_json, but eventually that don't send the message
|
|
server.PromptServer.instance.send_sync('crystools.monitor', data)
|
|
|
|
def startMonitorLoop(self):
|
|
# logger.debug('Starting monitor loop...')
|
|
asyncio.run(self.MonitorLoop())
|
|
|
|
async def MonitorLoop(self):
|
|
while self.rate > 0 and not self.threadController.is_set():
|
|
data = self.hardwareInfo.getStatus()
|
|
# logger.debug('data to send' + str(data))
|
|
await self.send_message(data)
|
|
await asyncio.sleep(self.rate)
|
|
|
|
def startMonitor(self):
|
|
if self.monitorThread is not None:
|
|
self.stopMonitor()
|
|
logger.debug('Restarting monitor...')
|
|
else:
|
|
if self.rate == 0:
|
|
logger.debug('Monitor rate is 0, not starting monitor.')
|
|
return None
|
|
|
|
logger.debug('Starting monitor...')
|
|
|
|
self.threadController.clear()
|
|
|
|
if self.monitorThread is None or not self.monitorThread.is_alive():
|
|
lock.acquire()
|
|
self.monitorThread = threading.Thread(target=self.startMonitorLoop)
|
|
lock.release()
|
|
self.monitorThread.daemon = True
|
|
self.monitorThread.start()
|
|
|
|
|
|
def stopMonitor(self):
|
|
logger.debug('Stopping monitor...')
|
|
self.threadController.set()
|
|
|
|
|
|
cmonitor = CMonitor(1, True, True, True, True, True)
|
|
|