diff --git a/src/sniffles/parallel.py b/src/sniffles/parallel.py index da7ad0b..060df91 100644 --- a/src/sniffles/parallel.py +++ b/src/sniffles/parallel.py @@ -611,28 +611,28 @@ def run_worker(self): t.start() while self.running: - try: - self._logger.debug(f'Worker {self.id} ({self.pid}) waiting for tasks...') + self._logger.debug(f'Worker {self.id} ({self.pid}) waiting for tasks...') - task = self.pipe_worker.recv() + task = self.pipe_worker.recv() - self._logger.debug(f'Worker {self.id} got task {task}') + self._logger.debug(f'Worker {self.id} got task {task}') + try: result = task.execute(self) - + except self.Shutdown: + self.running = False + self._shutdown.set() + except Exception as e: + self._logger.exception(msg := f'Error in worker process while executing {task}') + self.pipe_worker.send(ErrorResult(msg)) + else: self._logger.debug(f'Worker {self.id} finished executing {task}, sending back result...') if result is not None: self.pipe_worker.send(result) - del task - gc.collect() - except self.Shutdown: - self.running = False - self._shutdown.set() - except Exception as e: - self._logger.exception(f'Error in worker process') - self.pipe_worker.send(ErrorResult(e)) + del task + gc.collect() t.join(1.0) diff --git a/src/sniffles/result.py b/src/sniffles/result.py index f504e2b..ba1d42a 100644 --- a/src/sniffles/result.py +++ b/src/sniffles/result.py @@ -154,7 +154,7 @@ def store_calls(self, svcalls): if SnifflesConfig.GLOBAL.sort and svcalls: svcalls = list(sorted(svcalls, key=lambda call: call.pos)) - while svcalls[offset].pos < self._highest_position_call: + while offset < len(svcalls) and svcalls[offset].pos < self._highest_position_call: log.debug(f'Unsorted call detected: {self._highest_position_call} > {svcalls[0]}') offset += 1 @@ -206,8 +206,12 @@ def cleanup(self): class ErrorResult: error = True - def __init__(self, ex: Exception): - self.message = f'{ex}' + def __init__(self, msg: str): + self.message = msg def __str__(self): return self.message + + def emit(self, **kwargs) -> int: + log.error(f'{self.message}') + return 0