From 253fa3dfe81cd87c733af8f4db0df6f33b1d9cb5 Mon Sep 17 00:00:00 2001 From: Tadpole Date: Thu, 4 Feb 2016 12:52:34 +0100 Subject: [PATCH] Put output in separate thread to fix threadsearch delay --- api/irc.py | 13 ++++++++++--- bhottu.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api/irc.py b/api/irc.py index 45c04f7..b19dc6a 100644 --- a/api/irc.py +++ b/api/irc.py @@ -2,6 +2,7 @@ import log import ssl import Queue +import threading connection = None commandQueue = None @@ -29,6 +30,7 @@ def disconnect(): connection.shutdown(socket.SHUT_RDWR) connection.close() connection = None + commandQueue = None ## def readEvent(): @@ -46,11 +48,16 @@ def readEvent(): return None readbuffer += data -def sendAllCommands(): +def consumeAndSendCommands(): global commandQueue global connection - while not commandQueue.empty(): - connection.sendall(commandQueue.get()) + while True: + connection.sendall(commandQueue.get(block=True)) + +def startOutputThread(): + consumer = threading.Thread(target=consumeAndSendCommands) + consumer.setDaemon(True) + consumer.start() def sendCommand(command): global commandQueue diff --git a/bhottu.py b/bhottu.py index 1093f00..1b1823b 100755 --- a/bhottu.py +++ b/bhottu.py @@ -69,8 +69,8 @@ def main(): while True: if not makeConnection(): break + startOutputThread() while True: - sendAllCommands() event = readEvent() if event == None: break