36 lines
922 B
Python
36 lines
922 B
Python
from PyQt5.QtCore import QObject
|
|
import threading
|
|
|
|
class SharedStore(QObject):
|
|
_instance = None
|
|
_lock = threading.Lock()
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self._items = []
|
|
self._items_lock = threading.Lock()
|
|
|
|
@classmethod
|
|
def get_instance(cls):
|
|
if not cls._instance:
|
|
with cls._lock:
|
|
if not cls._instance:
|
|
cls._instance = SharedStore()
|
|
return cls._instance
|
|
|
|
def append(self, item: dict):
|
|
with self._items_lock:
|
|
self._items.append(item)
|
|
|
|
def remove(self, listed_id: int):
|
|
with self._items_lock:
|
|
self._items = [i for i in self._items if i["listed_id"] != listed_id]
|
|
|
|
def size(self) -> int:
|
|
with self._items_lock:
|
|
return len(self._items)
|
|
|
|
def get_items(self) -> list:
|
|
with self._items_lock:
|
|
return list(self._items)
|