This repository was archived by the owner on Nov 24, 2020. It is now read-only.
File tree 2 files changed +11
-4
lines changed
2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change 2
2
import log
3
3
import ssl
4
4
import Queue
5
+ import threading
5
6
6
7
connection = None
7
8
commandQueue = None
@@ -29,6 +30,7 @@ def disconnect():
29
30
connection .shutdown (socket .SHUT_RDWR )
30
31
connection .close ()
31
32
connection = None
33
+ commandQueue = None
32
34
33
35
##
34
36
def readEvent ():
@@ -46,11 +48,16 @@ def readEvent():
46
48
return None
47
49
readbuffer += data
48
50
49
- def sendAllCommands ():
51
+ def consumeAndSendCommands ():
50
52
global commandQueue
51
53
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 ()
54
61
55
62
def sendCommand (command ):
56
63
global commandQueue
Original file line number Diff line number Diff line change @@ -69,8 +69,8 @@ def main():
69
69
while True :
70
70
if not makeConnection ():
71
71
break
72
+ startOutputThread ()
72
73
while True :
73
- sendAllCommands ()
74
74
event = readEvent ()
75
75
if event == None :
76
76
break
You can’t perform that action at this time.
0 commit comments