Skip to content

Commit

Permalink
Merge pull request #11 from juaml/fix_exceptions_handling
Browse files Browse the repository at this point in the history
Fix_exceptions_handling
  • Loading branch information
fraimondo authored Jan 23, 2025
2 parents 134f644 + c390854 commit aeaac52
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/11.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug in which exceptions raised during delayed computation broke the backend without reporting the error and finishing.
3 changes: 1 addition & 2 deletions joblib_htcondor/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,7 @@ def _poll_jobs(self) -> tuple[int, bool]: # noqa: C901
level=9,
msg=f"Job {job_meta} raised an exception.",
)
typ, exc, tb = result
job_meta.tracking_future.set_exception(exc)
job_meta.tracking_future.set_exception(result)
else:
logger.log(
level=9,
Expand Down
71 changes: 71 additions & 0 deletions joblib_htcondor/tests/test_runtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Provide runtime tests."""

# Authors: Federico Raimondo <f.raimondo@fz-juelich.de>
# License: AGPL

import logging
import socket

import pytest
from joblib import Parallel, delayed, parallel_config

from joblib_htcondor import register_htcondor


# Check if the test is running on juseless
if socket.gethostname() != "juseless":
pytest.skip("These tests are only for juseless", allow_module_level=True)


register_htcondor()


def test_normal() -> None:
"""Test normal execution."""
from operator import neg

with parallel_config(
backend="htcondor", n_jobs=-1, request_cpus=1, request_memory="1Gb"
):
out = Parallel()(delayed(neg)(i + 1) for i in range(5))

assert out == [-1, -2, -3, -4, -5]


def test_exception() -> None:
"""Test running with an exception."""

def neg_with_exception(a: int) -> int:
"""Negate if a!=2, raise an exception otherwise.
Parameters
----------
a : int
The number to negate.
Returns
-------
int
The negated number.
Raises
------
ValueError
If `a` is 2.
"""
if a == 2:
raise ValueError("This is an exception")
else:
return -a

with parallel_config(
backend="htcondor",
n_jobs=-1,
request_cpus=1,
request_memory="1Gb",
verbose=1000,
worker_log_level=logging.INFO,
):
with pytest.raises(ValueError, match="This is an exception"):
Parallel()(delayed(neg_with_exception)(i + 1) for i in range(5))
4 changes: 4 additions & 0 deletions joblib_htcondor/ui/treeparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
from copy import copy
from datetime import datetime
from json.decoder import JSONDecodeError
from pathlib import Path

from ..backend import (
Expand Down Expand Up @@ -150,6 +151,9 @@ def update(self) -> None:
except OSError as e:
logger.error(f"Error loading {f}: {e}")
continue
except JSONDecodeError as e:
logger.error(f"Error decoding {f}: {e}")
continue
all_meta = sorted(all_meta, key=lambda x: x.meta.start_timestamp)
# Update the tree from this list of files
logger.log(
Expand Down

0 comments on commit aeaac52

Please sign in to comment.