Files
bmad4ever-comfyui_quilting/types.py
T
Bruno Madeira 506e67e2df Refactoring > added type for ui stuff.
I want to test an alternative approach to make the texture seamless, but, in order to re-use already existing code without using ui related stuff when testing all ui related args must be optional.
Bundling them within a single type simplifies the job and improves readability.
2024-07-10 01:54:28 +01:00

31 lines
933 B
Python

from multiprocessing.shared_memory import SharedMemory
from dataclasses import dataclass
import numpy as np
class UiCoordData:
def __init__(self, jobs_shm_name: str, job_id: int):
self.jobs_shm_name = jobs_shm_name
self.job_id = job_id
self.__shm: SharedMemory | None = None
def copy(self):
"""
@return: a copy with the same jobs_shm_name & job_id only; no shm_data.
"""
return UiCoordData(self.jobs_shm_name, self.job_id)
@property
def _shm(self):
if self.__shm is None:
self.__shm = SharedMemory(name=self.jobs_shm_name)
return self.__shm
def add_to_job_data_slot_and_check_interrupt(self, to_increment: int | np.uint32):
shm_data_array = np.ndarray((2 + self.job_id,), dtype=np.dtype('uint32'), buffer=self._shm.buf)
shm_data_array[1 + self.job_id] += to_increment
return shm_data_array[0] > 0