Skip to content

Commit fb1dbbe

Browse files
committed
refactor: improve handling of IOError issues in parallel tests (fix/docker-test...)
1 parent 8ef82f9 commit fb1dbbe

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

‎sklearn_porter/Estimator.py‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,21 @@ def make(
645645
):
646646
cmd_args['src_path'] = str(src_path)
647647

648+
paths_to_check = []
649+
if 'src_path' in cmd_args.keys():
650+
paths_to_check.append(cmd_args.get('src_path'))
651+
if 'dest_path' in cmd_args.keys():
652+
paths_to_check.append(cmd_args.get('dest_path'))
653+
for path_to_check in paths_to_check:
654+
for _ in range(10):
655+
try:
656+
fp = open(path_to_check)
657+
except IOError:
658+
sleep(0.1)
659+
else:
660+
fp.close()
661+
break
662+
648663
cmd = cmd.format(**cmd_args)
649664
L.info('Execution command: `{}`'.format(cmd))
650665

@@ -953,18 +968,23 @@ def _system_call(cmd: str, executable='/bin/bash'):
953968
stderr=STDOUT,
954969
executable=executable
955970
)
956-
for idx in range(5): # Try three times, b/c of `file is busy` issues.
971+
for _ in range(10):
957972
try:
958973
out = check_output(cmd, **subp_args)
959-
out = loads(out, encoding='utf-8')
960974
except CalledProcessError:
961-
sleep(0.01)
962-
except JSONDecodeError:
963-
sleep(0.01)
975+
sleep(0.1)
964976
else:
965-
if 'predict_proba' in out.keys():
966-
return [out.get('predict'), out.get('predict_proba')]
967-
return [out.get('predict')]
977+
try:
978+
out = loads(out, encoding='utf-8')
979+
except JSONDecodeError as e:
980+
L.error(e)
981+
else:
982+
result = []
983+
if 'predict' in out.keys():
984+
result.append(out.get('predict'))
985+
if 'predict_proba' in out.keys():
986+
result.append(out.get('predict_proba'))
987+
return result
968988

969989

970990
def show(language: Optional[Union[str, enum.Language]] = None):

0 commit comments

Comments
 (0)