@@ -67,13 +67,16 @@ def __init__(self, scriptPath):
6767 self .__serverProc = subprocess .Popen ([node_path , scriptPath ],
6868 stdin = subprocess .PIPE , stdout = subprocess .PIPE ,startupinfo = si )
6969 else :
70+ log .debug ("opening " + node_path + " " + scriptPath )
7071 self .__serverProc = subprocess .Popen ([node_path , scriptPath ],
7172 stdin = subprocess .PIPE , stdout = subprocess .PIPE )
72- except FileNotFoundError :
73+ except :
7374 self .__serverProc = None
7475 # start reader thread
75- if self .__serverProc :
76- readerThread = threading .Thread (target = NodeCommClient .__reader , args = (self .__serverProc .stdout , self .__msgq , self .__eventq , self .asyncReq ))
76+ if self .__serverProc and (not self .__serverProc .poll ()):
77+ log .debug ("server proc " + str (self .__serverProc ))
78+ log .debug ("starting reader thread" )
79+ readerThread = threading .Thread (target = NodeCommClient .__reader , args = (self .__serverProc .stdout , self .__msgq , self .__eventq , self .asyncReq , self .__serverProc ))
7780 readerThread .daemon = True
7881 readerThread .start ()
7982 self .__debugProc = None
@@ -157,7 +160,7 @@ def postCmd(self, cmd):
157160 """
158161 log .debug ('Posting command: {0}' .format (cmd ))
159162 if not self .__serverProc :
160- log .error ("can not send request; node process not started " )
163+ log .error ("can not send request; node process not running " )
161164 return False
162165 else :
163166 cmd = cmd + "\n "
@@ -176,7 +179,7 @@ def getEvent(self):
176179 return ev
177180
178181 @staticmethod
179- def __readMsg (stream , msgq , eventq , asyncReq ):
182+ def __readMsg (stream , msgq , eventq , asyncReq , proc ):
180183 """
181184 Reader thread helper
182185 """
@@ -190,7 +193,7 @@ def __readMsg(stream, msgq, eventq, asyncReq):
190193 if len (header ) == 0 :
191194 if state == 'init' :
192195 log .info ('0 byte line in stream when expecting header' )
193- return
196+ return proc . poll () != None
194197 else :
195198 state = "body"
196199 else :
@@ -210,23 +213,24 @@ def __readMsg(stream, msgq, eventq, asyncReq):
210213 callback = asyncReq .pop (request_seq , None )
211214 if callback :
212215 callback (dict )
213- return
216+ return False
214217 else :
215218 # Only put in the queue if wasn't an async request
216219 msgq .put (jsonStr )
217220 else :
218221 eventq .put (jsonStr )
219222 else :
220223 log .info ('Body length of 0 in server stream' )
221- return
224+ return False
222225
223226 @staticmethod
224- def __reader (stream , msgq , eventq , asyncReq ):
227+ def __reader (stream , msgq , eventq , asyncReq , proc ):
225228 """
226229 Main function for reader thread
227230 """
228231 while True :
229- NodeCommClient .__readMsg (stream , msgq , eventq , asyncReq )
232+ if NodeCommClient .__readMsg (stream , msgq , eventq , asyncReq , proc ):
233+ return
230234
231235 @staticmethod
232236 def __which (program ):
0 commit comments