-
Notifications
You must be signed in to change notification settings - Fork 1
/
abstractwriter.py
49 lines (39 loc) · 1.28 KB
/
abstractwriter.py
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
40
41
42
43
44
45
46
47
48
49
import logging
from queue import Queue
from threading import Thread, Event
from typing import Union
from abstractscreen import AbstractScreen
class AbstractWriter(Thread):
def __init__(self):
# call the thread class
super(AbstractWriter, self).__init__()
self.__event = Event()
self.sendQ = Queue()
self.setDaemon(True)
def stop(self):
self.__event.set()
def stopped(self) -> bool:
return self.__event.isSet()
def run(self):
try:
while not self.stopped():
item = self.sendQ.get()
self.handleItem(item)
self.sendQ.task_done()
except Exception as e:
logging.error("Error communicating")
logging.error(e, exc_info=True)
def handleItem(self, item: Union[str, bytes]):
"""
Processing item object
Children define specific procedures
:param item: Data type defined by respective children -
must be same as in the output method!
"""
raise NotImplementedError()
def output(self, screen: 'AbstractScreen'):
"""
Output screen to the displaying device. Overriden in children
:param screen: specific screen
"""
raise NotImplementedError()