provide information to the queue which entries are done

This commit is contained in:
Jakob Ketterl 2020-08-05 20:04:41 +02:00
parent a65fd7916e
commit 0518ff9358

View File

@ -26,21 +26,23 @@ logger = logging.getLogger(__name__)
class Client(ABC): class Client(ABC):
def __init__(self, conn): def __init__(self, conn):
self.conn = conn self.conn = conn
self.multithreadingPipe = Queue(100) self.multithreadingQueue = Queue(100)
def mp_passthru(): def mp_passthru():
run = True run = True
while run: while run:
try: try:
data = self.multithreadingPipe.get() data = self.multithreadingQueue.get()
self.send(data) self.send(data)
except (EOFError, OSError, ValueError): except (EOFError, OSError, ValueError):
run = False run = False
except Exception: except Exception:
logger.exception("Exception on client multithreading queue") logger.exception("Exception on client multithreading queue")
finally:
self.multithreadingQueue.task_done()
# unset the queue object to free shared memory file descriptors # unset the queue object to free shared memory file descriptors
self.multithreadingPipe = None self.multithreadingQueue = None
threading.Thread(target=mp_passthru).start() threading.Thread(target=mp_passthru).start()
@ -54,10 +56,10 @@ class Client(ABC):
self.conn.close() self.conn.close()
def mp_send(self, data): def mp_send(self, data):
if self.multithreadingPipe is None: if self.multithreadingQueue is None:
return return
try: try:
self.multithreadingPipe.put(data, block=False) self.multithreadingQueue.put(data, block=False)
except Full: except Full:
self.close() self.close()