-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueuemgr.py
More file actions
39 lines (31 loc) · 1007 Bytes
/
queuemgr.py
File metadata and controls
39 lines (31 loc) · 1007 Bytes
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
import threading
import time
class QueueManager(list):
"""
QueueManager
Item-Syntax: (description , function )
e.g.: ('Printing hello world', lambda: print('Hello world'))
"""
def __init__(self, on_change) -> None:
self.on_change = on_change
self._queue_thread = threading.Thread(target=self._loop, daemon=True)
self._queue_thread.start()
def _loop(self) -> None:
while True:
if len(self):
if self[0][1] == "break":
break
else:
self.on_change()
self[0][1]()
del self[0]
else:
time.sleep(2)
def dump(self) -> list:
return [task[0] for task in self]
def append(self, object) -> None:
super().append(object)
self.on_change()
def __delitem__(self, key, /) -> None:
super().__delitem__(key)
self.on_change()