@@ -13,7 +13,7 @@ def now():
1313 return round (time .time () * 1000 )
1414
1515class ImpulseRunner :
16- def __init__ (self , model_path : str ):
16+ def __init__ (self , model_path : str , timeout : int = 5 ):
1717 self ._model_path = model_path
1818 self ._tempdir = None
1919 self ._runner = None
@@ -22,6 +22,7 @@ def __init__(self, model_path: str):
2222 self ._debug = False
2323 self ._hello_resp = None
2424 self ._shm = None
25+ self ._timeout = timeout
2526
2627 def init (self , debug = False ):
2728 if not os .path .exists (self ._model_path ):
@@ -39,8 +40,8 @@ def init(self, debug=False):
3940 else :
4041 self ._runner = subprocess .Popen (
4142 cmd ,
42- stdout = subprocess .PIPE ,
43- stderr = subprocess .PIPE ,
43+ stdout = subprocess .DEVNULL ,
44+ stderr = subprocess .DEVNULL ,
4445 )
4546
4647 while not os .path .exists (socket_path ) or self ._runner .poll () is not None :
@@ -50,6 +51,8 @@ def init(self, debug=False):
5051 raise Exception ("Failed to start runner (" + str (self ._runner .poll ()) + ")" )
5152
5253 self ._client = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM )
54+ # timeout the IPC connection in case the EIM hangs
55+ self ._client .settimeout (self ._timeout )
5356 self ._client .connect (socket_path )
5457
5558 hello_resp = self ._hello_resp = self .hello ()
0 commit comments