From e26140c43598325a27c34c6c92d15263e037933e Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 8 May 2014 14:41:21 -0700 Subject: [PATCH] Handle failure to read JSON waiting for server start If the test controller tries to read the file while the server it has started is in the middle of writing it, it gets invalid JSON and fails. This just loops again until we have valid JSON to read. --- IPython/testing/iptestcontroller.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/IPython/testing/iptestcontroller.py b/IPython/testing/iptestcontroller.py index df2957980..d72aa8811 100644 --- a/IPython/testing/iptestcontroller.py +++ b/IPython/testing/iptestcontroller.py @@ -274,8 +274,14 @@ class JSController(TestController): if self.server.poll() is not None: return self._failed_to_start() if os.path.exists(self.server_info_file): - self._load_server_info() - return + try: + self._load_server_info() + except ValueError: + # If the server is halfway through writing the file, we may + # get invalid JSON; it should be ready next iteration. + pass + else: + return time.sleep(0.1) print("Notebook server-info file never arrived: %s" % self.server_info_file, file=sys.stderr