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

Commit 253fa3d

Browse files
committed
Put output in separate thread to fix threadsearch delay
1 parent bc25286 commit 253fa3d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

api/irc.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import log
33
import ssl
44
import Queue
5+
import threading
56

67
connection = None
78
commandQueue = None
@@ -29,6 +30,7 @@ def disconnect():
2930
connection.shutdown(socket.SHUT_RDWR)
3031
connection.close()
3132
connection = None
33+
commandQueue = None
3234

3335
##
3436
def readEvent():
@@ -46,11 +48,16 @@ def readEvent():
4648
return None
4749
readbuffer += data
4850

49-
def sendAllCommands():
51+
def consumeAndSendCommands():
5052
global commandQueue
5153
global connection
52-
while not commandQueue.empty():
53-
connection.sendall(commandQueue.get())
54+
while True:
55+
connection.sendall(commandQueue.get(block=True))
56+
57+
def startOutputThread():
58+
consumer = threading.Thread(target=consumeAndSendCommands)
59+
consumer.setDaemon(True)
60+
consumer.start()
5461

5562
def sendCommand(command):
5663
global commandQueue

bhottu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def main():
6969
while True:
7070
if not makeConnection():
7171
break
72+
startOutputThread()
7273
while True:
73-
sendAllCommands()
7474
event = readEvent()
7575
if event == None:
7676
break

0 commit comments

Comments
 (0)