ipnbdoctest: attempt to restart when the kernel dies

* tests/python/ipnbdoctest.py: Catch kernel deaths, wait a random
number of seconds, and try again up to three times.
This commit is contained in:
Alexandre Duret-Lutz 2020-01-04 17:59:45 +01:00
parent d8ed0fb8ab
commit fd92d20fd3

View file

@ -18,6 +18,7 @@ import time
import base64 import base64
import re import re
import pprint import pprint
import random
from difflib import unified_diff as diff from difflib import unified_diff as diff
from collections import defaultdict from collections import defaultdict
@ -324,5 +325,20 @@ def test_notebook(ipynb):
if __name__ == '__main__': if __name__ == '__main__':
for ipynb in sys.argv[1:]: for ipynb in sys.argv[1:]:
print("testing %s" % ipynb) tries=3
test_notebook(ipynb) while tries:
print("testing %s" % ipynb)
try:
test_notebook(ipynb)
break
except RuntimeError as e:
# If the Kernel dies, try again. It seems we have spurious
# failures when multiple instances of jupyter start in parallel.
if 'Kernel died' in str(e):
tries -= 1
if tries:
s = random.randint(1, 5)
print("trying again in", s, "seconds...")
time.sleep(s)
else:
raise e