From 036ff870579c4c24dd81c2d3d71755b2a4cef88a Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Sat, 7 May 2016 23:21:53 +0200 Subject: [PATCH 1/3] remove enqueue kwarg in Loop.run --- qcodes/loops.py | 15 +++++++-------- qcodes/tests/test_loop.py | 24 ++++++++++++++++++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/qcodes/loops.py b/qcodes/loops.py index e4dabc831226..fb8666c0beac 100644 --- a/qcodes/loops.py +++ b/qcodes/loops.py @@ -409,7 +409,7 @@ def run_temp(self, **kwargs): return self.run(background=False, quiet=True, data_manager=False, location=False, **kwargs) - def run(self, background=True, use_threads=True, enqueue=False, + def run(self, background=True, use_threads=True, quiet=False, data_manager=None, **kwargs): ''' execute this loop @@ -419,8 +419,6 @@ def run(self, background=True, use_threads=True, enqueue=False, use_threads: (default True): whenever there are multiple `get` calls back-to-back, execute them in separate threads so they run in parallel (as long as they don't block each other) - enqueue: (default False): wait for a previous background sweep to - finish? If false, will raise an error if another sweep is running quiet: (default False): set True to not print anything except errors data_manager: a DataManager instance (omit to use default, False to store locally) @@ -446,11 +444,9 @@ def run(self, background=True, use_threads=True, enqueue=False, prev_loop = get_bg() if prev_loop: - if enqueue: - prev_loop.join() # wait until previous loop finishes - else: - raise RuntimeError( - 'a loop is already running in the background') + print('Waiting for the previous background Loop to finish...') + prev_loop.join() + if data_manager is False: data_mode = DataMode.LOCAL else: @@ -461,6 +457,9 @@ def run(self, background=True, use_threads=True, enqueue=False, self.set_common_attrs(data_set=data_set, use_threads=use_threads, signal_queue=self.signal_queue) + if prev_loop: + print('...done. Starting ' + (data_set.location or 'new loop')) + if background: p = QcodesProcess(target=self._run_wrapper, name=MP_NAME) p.is_sweep = True diff --git a/qcodes/tests/test_loop.py b/qcodes/tests/test_loop.py index 2af44ecd0134..2adb936dd945 100644 --- a/qcodes/tests/test_loop.py +++ b/qcodes/tests/test_loop.py @@ -106,12 +106,28 @@ def test_foreground_no_datamanager(self): def test_enqueue(self): c1 = self.gates.chan1 loop = Loop(c1[1:5:1], 0.01).each(c1) - loop.run(location=self.location, quiet=True) + data1 = loop.run(location=self.location, quiet=True) + + # second running of the loop should be enqueued, blocks until + # the first one finishes. + # TODO: check what it prints? + data2 = loop.run(location=self.location2, quiet=True) + + data1.sync() + data2.sync() + self.assertEqual(data1.chan1.tolist(), [1, 2, 3, 4]) + for v in data2.chan1: + self.assertTrue(np.isnan(v)) - with self.assertRaises(RuntimeError): - loop.run(location=self.location2, quiet=True) - loop.run(location=self.location2, quiet=True, enqueue=True) loop.process.join() + data2.sync() + self.assertEqual(data2.chan1.tolist(), [1, 2, 3, 4]) + + # and while we're here, check that running a loop in the + # foreground *after* the background clears its .process + self.assertTrue(hasattr(loop, 'process')) + loop.run_temp() + self.assertFalse(hasattr(loop, 'process')) def sleeper(t): From 21dc62e6e1bec77861638ce234fb7f032e73aae7 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Sat, 7 May 2016 23:29:58 +0200 Subject: [PATCH 2/3] flush so we see the "waiting" message immediately --- qcodes/loops.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qcodes/loops.py b/qcodes/loops.py index fb8666c0beac..1afffe707ac5 100644 --- a/qcodes/loops.py +++ b/qcodes/loops.py @@ -444,7 +444,8 @@ def run(self, background=True, use_threads=True, prev_loop = get_bg() if prev_loop: - print('Waiting for the previous background Loop to finish...') + print('Waiting for the previous background Loop to finish...', + flush=True) prev_loop.join() if data_manager is False: @@ -458,7 +459,8 @@ def run(self, background=True, use_threads=True, signal_queue=self.signal_queue) if prev_loop: - print('...done. Starting ' + (data_set.location or 'new loop')) + print('...done. Starting ' + (data_set.location or 'new loop'), + flush=True) if background: p = QcodesProcess(target=self._run_wrapper, name=MP_NAME) From 23480d2fdc4c2fed553aa2c0d95c696ba66226eb Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Sat, 7 May 2016 23:40:39 +0200 Subject: [PATCH 3/3] queue messages should respect quiet --- qcodes/loops.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qcodes/loops.py b/qcodes/loops.py index 1afffe707ac5..9917eb58d9d6 100644 --- a/qcodes/loops.py +++ b/qcodes/loops.py @@ -444,8 +444,9 @@ def run(self, background=True, use_threads=True, prev_loop = get_bg() if prev_loop: - print('Waiting for the previous background Loop to finish...', - flush=True) + if not quiet: + print('Waiting for the previous background Loop to finish...', + flush=True) prev_loop.join() if data_manager is False: @@ -458,7 +459,7 @@ def run(self, background=True, use_threads=True, self.set_common_attrs(data_set=data_set, use_threads=use_threads, signal_queue=self.signal_queue) - if prev_loop: + if prev_loop and not quiet: print('...done. Starting ' + (data_set.location or 'new loop'), flush=True)