Skip to content

Commit

Permalink
Finish debugging file occupation error in windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavdGao committed Jul 30, 2024
1 parent 2de1348 commit 3e4089e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/agentscope/manager/_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ def _create_monitor_db(self) -> None:

self.session = sessionmaker(bind=self.engine)

def _close_monitor_db(self) -> None:
"""Close the monitor database to avoid file occupation error in
windows."""
if self.session is not None:
self.session.dispose()

if self.engine is not None:
self.engine.close_all()

def update_image_tokens(
self,
model_name: str,
Expand Down Expand Up @@ -318,6 +327,9 @@ def deserialize(self, data: dict) -> None:

def flush(self) -> None:
"""Flush the monitor manager."""
# Close the database before flushing
self._close_monitor_db()

self.use_monitor = False
self.session = None
self.engine = None
Expand Down
6 changes: 3 additions & 3 deletions tests/monitor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import os
import shutil
from pathlib import Path
from loguru import logger

import agentscope
from agentscope.manager import MonitorManager
from agentscope.manager import MonitorManager, ASManager


class MonitorManagerTest(unittest.TestCase):
Expand Down Expand Up @@ -93,6 +92,7 @@ def test_monitor(self) -> None:

def tearDown(self) -> None:
"""Tear down the test environment."""
ASManager.get_instance().flush()
shutil.rmtree("./test_runs")


Expand Down Expand Up @@ -148,7 +148,7 @@ def test_disabled_monitor(self) -> None:

def tearDown(self) -> None:
"""Tear down the test environment."""
logger.remove()
ASManager.get_instance().flush()
shutil.rmtree("./test_runs")


Expand Down

0 comments on commit 3e4089e

Please sign in to comment.