|
|
|
|
@ -27,6 +27,23 @@ from IPython.utils.py3compat import bytes_to_str
|
|
|
|
|
from IPython.utils.sysinfo import get_sys_info
|
|
|
|
|
from IPython.utils.tempdir import TemporaryDirectory
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# Python >= 3.3
|
|
|
|
|
from subprocess import TimeoutExpired
|
|
|
|
|
def popen_wait(p, timeout):
|
|
|
|
|
return p.wait(timeout)
|
|
|
|
|
except ImportError:
|
|
|
|
|
class TimeoutExpired(Exception):
|
|
|
|
|
pass
|
|
|
|
|
def popen_wait(p, timeout):
|
|
|
|
|
"""backport of Popen.wait from Python 3"""
|
|
|
|
|
for i in range(int(10 * timeout)):
|
|
|
|
|
if p.poll() is not None:
|
|
|
|
|
return
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
if p.poll() is None:
|
|
|
|
|
raise TimeoutExpired
|
|
|
|
|
|
|
|
|
|
NOTEBOOK_SHUTDOWN_TIMEOUT = 10
|
|
|
|
|
|
|
|
|
|
class TestController(object):
|
|
|
|
|
@ -283,8 +300,8 @@ class JSController(TestController):
|
|
|
|
|
pass
|
|
|
|
|
# wait 10s for the server to shutdown
|
|
|
|
|
try:
|
|
|
|
|
self.server.wait(NOTEBOOK_SHUTDOWN_TIMEOUT)
|
|
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
|
popen_wait(self.server, NOTEBOOK_SHUTDOWN_TIMEOUT)
|
|
|
|
|
except TimeoutExpired:
|
|
|
|
|
# server didn't terminate, kill it
|
|
|
|
|
try:
|
|
|
|
|
print("Failed to terminate notebook server, killing it.",
|
|
|
|
|
@ -296,8 +313,8 @@ class JSController(TestController):
|
|
|
|
|
pass
|
|
|
|
|
# wait another 10s
|
|
|
|
|
try:
|
|
|
|
|
self.server.wait(NOTEBOOK_SHUTDOWN_TIMEOUT)
|
|
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
|
popen_wait(self.server, NOTEBOOK_SHUTDOWN_TIMEOUT)
|
|
|
|
|
except TimeoutExpired:
|
|
|
|
|
print("Notebook server still running (%s)" % self.server_info_file,
|
|
|
|
|
file=sys.stderr
|
|
|
|
|
)
|
|
|
|
|
|