Skip to content

Commit e824810

Browse files
committed
Set IP timeout to 5 seconds (configurable)
1 parent c8027ae commit e824810

File tree

8 files changed

+11
-8
lines changed

8 files changed

+11
-8
lines changed

edge_impulse_linux/runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def now():
1313
return round(time.time() * 1000)
1414

1515
class 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):
@@ -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()

examples/audio/classify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def main(argv):
4141
with AudioImpulseRunner(modelfile) as runner:
4242
try:
4343
model_info = runner.init()
44-
# model_info = runner.init(debug=True) # to get debug print out
44+
# model_info = runner.init(debug=True, timeout=10) # to get debug print out and set longer timeout
4545
labels = model_info['model_parameters']['labels']
4646
print('Loaded runner for "' + model_info['project']['owner'] + ' / ' + model_info['project']['name'] + '"')
4747

examples/custom/classify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def main(argv):
5454
runner = ImpulseRunner(modelfile)
5555
try:
5656
model_info = runner.init()
57-
# model_info = runner.init(debug=True) # to get debug print out
57+
# model_info = runner.init(debug=True, timeout=10) # to get debug print out and set longer timeout
5858

5959
print('Loaded runner for "' + model_info['project']['owner'] + ' / ' + model_info['project']['name'] + '"')
6060

examples/image/classify-full-frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def main(argv):
7171
with ImageImpulseRunner(modelfile) as runner:
7272
try:
7373
model_info = runner.init()
74-
# model_info = runner.init(debug=True) # to get debug print out
74+
# model_info = runner.init(debug=True, timeout=10) # to get debug print out and set longer timeout
7575

7676
print('Loaded runner for "' + model_info['project']['owner'] + ' / ' + model_info['project']['name'] + '"')
7777
labels = model_info['model_parameters']['labels']

examples/image/classify-image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def main(argv):
4343
with ImageImpulseRunner(modelfile) as runner:
4444
try:
4545
model_info = runner.init()
46-
# model_info = runner.init(debug=True) # to get debug print out
46+
# model_info = runner.init(debug=True, timeout=10) # to get debug print out and set longer timeout
4747

4848
print('Loaded runner for "' + model_info['project']['owner'] + ' / ' + model_info['project']['name'] + '"')
4949
labels = model_info['model_parameters']['labels']

examples/image/classify-video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main(argv):
4848
with ImageImpulseRunner(modelfile) as runner:
4949
try:
5050
model_info = runner.init()
51-
# model_info = runner.init(debug=True) # to get debug print out
51+
# model_info = runner.init(debug=True, timeout=10) # to get debug print out and set longer timeout
5252
print('Loaded runner for "' + model_info['project']['owner'] + ' / ' + model_info['project']['name'] + '"')
5353
labels = model_info['model_parameters']['labels']
5454

examples/image/classify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def main(argv):
7575
with ImageImpulseRunner(modelfile) as runner:
7676
try:
7777
model_info = runner.init()
78-
# model_info = runner.init(debug=True) # to get debug print out
78+
# model_info = runner.init(debug=True, timeout=10) # to get debug print out and set longer timeout
7979
print('Loaded runner for "' + model_info['project']['owner'] + ' / ' + model_info['project']['name'] + '"')
8080
labels = model_info['model_parameters']['labels']
8181
if len(args)>= 2:

examples/image/set-thresholds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def main(argv):
4444
with ImageImpulseRunner(modelfile) as runner:
4545
try:
4646
model_info = runner.init()
47-
# model_info = runner.init(debug=True) # to get debug print out
47+
# model_info = runner.init(debug=True, timeout=10) # to get debug print out and set longer timeout
4848

4949
print('Loaded runner for "' + model_info['project']['owner'] + ' / ' + model_info['project']['name'] + '"')
5050
if not 'thresholds' in model_info['model_parameters']:

0 commit comments

Comments
 (0)