Skip to content

Commit

Permalink
fix: Log exception and exit (#505)
Browse files Browse the repository at this point in the history
* fix: Log exception and exit

Closes #504

* fix: Do not return early

According to this principle from Alej "once is never, twice is always."
See pr comments.
  • Loading branch information
giulioungaretti authored Mar 2, 2017
1 parent 50388b1 commit 20bbdd9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions qcodes/loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"""

from datetime import datetime
import logging
import multiprocessing as mp
import time
import numpy as np
Expand All @@ -64,6 +65,8 @@
from .actions import (_actions_snapshot, Task, Wait, _Measure, _Nest,
BreakIf, _QcodesBreak)


log = logging.getLogger(__name__)
# Switches off multiprocessing by default, cant' be altered after module
USE_MP = config.core.legacy_mp
MP_NAME = 'Measurement'
Expand Down Expand Up @@ -870,7 +873,6 @@ def run(self, background=USE_MP, use_threads=False, quiet=False,
# this one later.
self.data_set = None


return ds

def _compile_actions(self, actions, action_indices=()):
Expand Down Expand Up @@ -939,8 +941,10 @@ def _run_loop(self, first_delay=0, action_indices=(),

t0 = time.time()
last_task = t0
last_task_failed = False
imax = len(self.sweep_values)

self.last_task_failed = False

for i, value in enumerate(self.sweep_values):
if self.progress_interval is not None:
tprint('loop %s: %d/%d (%.1f [s])' % (
Expand Down Expand Up @@ -997,16 +1001,18 @@ def _run_loop(self, first_delay=0, action_indices=(),
if t - last_task >= self.bg_min_delay:
try:
self.bg_task()
last_task_failed = False
except Exception:
if last_task_failed:
if self.last_task_failed:
self.bg_task = None
last_task_failed = True
self.last_task_failed = True
log.exception("Failed to execute bg task")

last_task = t

if self.progress_interval is not None:
# final progress note: set dt=-1 so it *always* prints
tprint('loop %s DONE: %d/%d (%.1f [s])' % (

self.sweep_values.name, i + 1, imax, time.time() - t0),
dt=-1, tag='outerloop')

Expand All @@ -1022,8 +1028,6 @@ def _run_loop(self, first_delay=0, action_indices=(),
if self.bg_final_task is not None:
self.bg_final_task()



def _wait(self, delay):
if delay:
finish_clock = time.perf_counter() + delay
Expand Down

0 comments on commit 20bbdd9

Please sign in to comment.