Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer use AbstractContextManager #1130

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions spinn_front_end_common/utilities/base_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import os
import sqlite3
import time
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

Expand All @@ -29,7 +28,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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import logging
from concurrent.futures import ThreadPoolExecutor, wait # @UnresolvedImport
from spinn_utilities.abstract_context_manager import AbstractContextManager
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
Expand All @@ -30,7 +29,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.
Expand Down
16 changes: 12 additions & 4 deletions spinn_front_end_common/utilities/sqlite_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
import pathlib
import sqlite3
import struct
from spinn_utilities.abstract_context_manager import AbstractContextManager
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.
Expand Down Expand Up @@ -122,6 +121,12 @@ def __init__(self, database_file=None, *, read_only=False, ddl_file=None,
self.__cursor = None

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:
Expand All @@ -130,15 +135,18 @@ 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:
self.__db.commit()
else:
self.__db.rollback()
self.__cursor = None
# calls close
return super().__exit__(exc_type, exc_val, exc_tb)
self.close()

def __del__(self):
self.close()
Expand Down