Skip to content

Commit

Permalink
asi_tpx3: don't crash in cancelled scan
Browse files Browse the repository at this point in the history
Happens often at the beginning of the acquisition, before
synchronization is complete
  • Loading branch information
sk1p committed Jun 23, 2023
1 parent 1282a23 commit 6360c03
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/libertem_live/detectors/asi_tpx3/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@

from libertem.common import Shape, Slice
from libertem.common.math import prod
from libertem.common.executor import WorkerContext, TaskProtocol, WorkerQueue, TaskCommHandler
from libertem.common.executor import (
WorkerContext, TaskProtocol, WorkerQueue, TaskCommHandler,
JobCancelledError,
)
from libertem.io.dataset.base import (
DataTile, DataSetMeta, BasePartition, Partition, DataSet, TilingScheme,
)
from libertem.corrections.corrset import CorrectionSet

from libertem_live.detectors.base.acquisition import AcquisitionMixin
from libertem_live.detectors.base.acquisition import (
AcquisitionMixin,
)
from libertem_live.detectors.base.controller import AcquisitionController
from libertem_live.hooks import ReadyForDataEnv, Hooks
from .connection import AsiTpx3DetectorConnection, AsiTpx3PendingAcquisition
Expand Down Expand Up @@ -101,14 +106,17 @@ def handle_task(self, task: TaskProtocol, queue: WorkerQueue):
chunk_stack = self.conn.get_next_stack(
max_size=current_stack_size
)
if chunk_stack is None:
if current_idx != end_idx:
queue.put({
"type": "END_PARTITION",
})
raise JobCancelledError("premature end of frame iterator")
break
assert len(chunk_stack) <= current_stack_size,\
f"{len(chunk_stack)} <= {current_stack_size}"
t1 = time.perf_counter()
recv_time += t1 - t0
if chunk_stack is None:
if current_idx != end_idx:
raise RuntimeError("premature end of frame iterator")
break

t0 = time.perf_counter()
serialized = chunk_stack.serialize()
Expand Down Expand Up @@ -343,8 +351,10 @@ def _get_tiles_straight(
try:
stack = next(stacks)
except StopIteration:
assert to_read == 0, f"we were still expecting to read {to_read} frames more!"

if to_read != 0:
raise JobCancelledError(
f"we were still expecting to read {to_read} frames more!"
)
for (
chunk_layout,
chunk_indptr,
Expand Down

0 comments on commit 6360c03

Please sign in to comment.