Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Commit

Permalink
Put output in separate thread to fix threadsearch delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyubis committed Feb 4, 2016
1 parent bc25286 commit 253fa3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions api/irc.py
Expand Up @@ -2,6 +2,7 @@
import log
import ssl
import Queue
import threading

connection = None
commandQueue = None
Expand Down Expand Up @@ -29,6 +30,7 @@ def disconnect():
connection.shutdown(socket.SHUT_RDWR)
connection.close()
connection = None
commandQueue = None

##
def readEvent():
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bhottu.py
Expand Up @@ -69,8 +69,8 @@ def main():
while True:
if not makeConnection():
break
startOutputThread()
while True:
sendAllCommands()
event = readEvent()
if event == None:
break
Expand Down

0 comments on commit 253fa3d

Please sign in to comment.