diff --git a/spinn_front_end_common/utilities/base_database.py b/spinn_front_end_common/utilities/base_database.py index 6524ec67ef..bf941dcd8e 100644 --- a/spinn_front_end_common/utilities/base_database.py +++ b/spinn_front_end_common/utilities/base_database.py @@ -17,7 +17,6 @@ import time from typing import Optional, Union from typing_extensions import TypeAlias -from spinn_utilities.abstract_context_manager import AbstractContextManager from spinn_front_end_common.data import FecDataView from spinn_front_end_common.utilities.sqlite_db import SQLiteDB @@ -31,7 +30,7 @@ def _timestamp(): return int(time.time() * _SECONDS_TO_MICRO_SECONDS_CONVERSION) -class BaseDatabase(SQLiteDB, AbstractContextManager): +class BaseDatabase(SQLiteDB): """ Specific implementation of the Database for SQLite 3. diff --git a/spinn_front_end_common/utilities/notification_protocol/notification_protocol.py b/spinn_front_end_common/utilities/notification_protocol/notification_protocol.py index 40445184c4..2041b65925 100644 --- a/spinn_front_end_common/utilities/notification_protocol/notification_protocol.py +++ b/spinn_front_end_common/utilities/notification_protocol/notification_protocol.py @@ -14,9 +14,8 @@ import logging from typing import List, Optional -from concurrent.futures import ( - Future, ThreadPoolExecutor, wait) -from spinn_utilities.abstract_context_manager import AbstractContextManager +from concurrent.futures import Future +from concurrent.futures import ThreadPoolExecutor, wait # @UnresolvedImport from spinn_utilities.config_holder import get_config_bool, get_config_int from spinn_utilities.log import FormatAdapter from spinnman.connections.udp_packet_connections import EIEIOConnection @@ -33,7 +32,7 @@ logger = FormatAdapter(logging.getLogger(__name__)) -class NotificationProtocol(AbstractContextManager): +class NotificationProtocol(object): """ The protocol which hand shakes with external devices about the database and starting execution. diff --git a/spinn_front_end_common/utilities/sqlite_db.py b/spinn_front_end_common/utilities/sqlite_db.py index e884681a62..fe1213835c 100644 --- a/spinn_front_end_common/utilities/sqlite_db.py +++ b/spinn_front_end_common/utilities/sqlite_db.py @@ -20,14 +20,13 @@ import sqlite3 import struct from typing import Optional, Type, Union -from spinn_utilities.abstract_context_manager import AbstractContextManager from pacman.exceptions import PacmanValueError from spinn_front_end_common.utilities.exceptions import DatabaseException logger = logging.getLogger(__name__) -class SQLiteDB(AbstractContextManager): +class SQLiteDB(object): """ General support class for SQLite databases. This handles a lot of the low-level detail of setting up a connection. @@ -150,6 +149,12 @@ def __init__( self.__pragma("trusted_schema", False) def _context_entered(self): + """ + Work to do when then context is entered. + + May be extended by super classes + + """ if self.__db is None: raise DatabaseException("database has been closed") if self.__cursor is not None: @@ -158,6 +163,10 @@ def _context_entered(self): self.__db.execute("BEGIN") self.__cursor = self.__db.cursor() + def __enter__(self): + self._context_entered() + return self + def __exit__(self, exc_type, exc_val, exc_tb): if self.__db is not None: if exc_type is None: @@ -165,8 +174,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): else: self.__db.rollback() self.__cursor = None - # calls close - return super().__exit__(exc_type, exc_val, exc_tb) + self.close() def __del__(self) -> None: self.close()