Skip to content

Commit

Permalink
make SpallocJob a contextlib.AbstractContextManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Nov 13, 2024
1 parent 6a501ae commit ddeef41
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions spinnman/spalloc/spalloc_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from contextlib import AbstractContextManager
from types import TracebackType
from typing import Dict, Mapping, Optional, Tuple, Type
from typing_extensions import Literal, Self

from spinn_utilities.abstract_base import AbstractBase, abstractmethod
from spinn_utilities.abstract_base import abstractmethod
from spinnman.constants import SCP_SCAMP_PORT
from spinnman.transceiver.transceiver import Transceiver
from spinnman.connections.udp_packet_connections import UDPConnection
Expand All @@ -27,7 +28,7 @@
from .spalloc_scp_connection import SpallocSCPConnection


class SpallocJob(object, metaclass=AbstractBase):
class SpallocJob(AbstractContextManager):
"""
Represents a job in Spalloc.
Expand Down Expand Up @@ -216,8 +217,9 @@ def __enter__(self) -> Self:
"""
return self

def __exit__(self, exc_type: Optional[Type], exc_value: Exception,
exc_tb: TracebackType) -> Literal[False]:
def __exit__(self, exc_type: Optional[Type],
exc_value: Optional[BaseException],
exc_tb: Optional[TracebackType]) -> Literal[False]:
"""
Handle exceptions by killing the job and logging the exception in the
job's destroy reason.
Expand Down

0 comments on commit ddeef41

Please sign in to comment.