Skip to content

Commit

Permalink
Merge branch 'refs/heads/issue520' into master-pub
Browse files Browse the repository at this point in the history
  • Loading branch information
Hermann Romanek committed Nov 11, 2024
2 parents f21b8ef + b15dcac commit 582d694
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
26 changes: 13 additions & 13 deletions src/sniffles/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 7 additions & 3 deletions src/sniffles/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 582d694

Please sign in to comment.