Skip to content

Commit

Permalink
reset database cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Dec 3, 2024
1 parent a292aaf commit aef8275
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions spynnaker/pyNN/models/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def csv_neo_block(

wrote_metadata = False
for segment in range(SpynnakerDataView.get_reset_number()):
with NeoBufferDatabase.segement_db(segment) as db:
with NeoBufferDatabase.reset_db(segment) as db:
if not wrote_metadata:
wrote_metadata = db.csv_block_metadata(
csv_file, pop_label, annotations)
Expand Down Expand Up @@ -335,7 +335,7 @@ def __append_previous_segment(
~spinn_front_end_common.utilities.exceptions.ConfigurationException:
If the recording not setup correctly
"""
with NeoBufferDatabase.segement_db(
with NeoBufferDatabase.reset_db(
segment_number, read_only=not clear) as db:
if block is None:
block = db.get_empty_block(
Expand Down
14 changes: 5 additions & 9 deletions spynnaker/pyNN/utilities/neo_buffer_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@

logger = FormatAdapter(logging.getLogger(__name__))

segment_cache: Dict[int, str] = {}


class NeoBufferDatabase(BufferDatabase, NeoCsv):
"""
Expand Down Expand Up @@ -116,24 +114,22 @@ def __init__(self, database_file: Optional[str] = None,
if read_only is None:
read_only = True

existed = os.path.exists(database_file)
super().__init__(database_file, read_only=read_only)

segment = SpynnakerDataView.get_reset_number()
if (segment not in segment_cache or
segment_cache[segment] != database_file):
if not existed:
with open(self.__NEO_DDL_FILE, encoding="utf-8") as f:
sql = f.read()
# pylint: disable=no-member
self._SQLiteDB__db.executescript(sql) # type: ignore[attr-defined]
segment_cache[segment] = database_file

@classmethod
def segement_db(cls, segment_number: int,
read_only: Optional[bool] = None) -> NeoBufferDatabase:
def reset_db(cls, reset_number: int,
read_only: Optional[bool] = None) -> NeoBufferDatabase:
"""
Retrieves a NeoBufferDatabase for this segment.
"""
database_file = segment_cache[segment_number]
database_file = cls.reset_file(reset_number)
return NeoBufferDatabase(database_file, read_only)

def write_segment_metadata(self) -> None:
Expand Down

0 comments on commit aef8275

Please sign in to comment.