Skip to content

Commit 2da9f17

Browse files
committed
use weakref.finalize to close plots
1 parent 30bf764 commit 2da9f17

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

iblrig/base_choice_world.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ def _run(self):
818818
)
819819
super()._run()
820820

821-
def __del__(self):
821+
def _finalize(self):
822822
if isinstance(self.plot_subprocess, subprocess.Popen) and self.plot_subprocess.poll() is None:
823823
log.info('Terminating subprocess: online plots')
824824
self.plot_subprocess.terminate()

iblrig/base_tasks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import sys
1717
import time
1818
import traceback
19+
import weakref
1920
from abc import ABC, abstractmethod
2021
from collections import OrderedDict
2122
from collections.abc import Callable
@@ -201,6 +202,10 @@ def __init__(
201202
stub,
202203
extractors=self.extractor_tasks,
203204
)
205+
self.finalize = weakref.finalize(self, self._finalize)
206+
207+
def _finalize(self): # noqa: B027
208+
"""Clean-up tasks prior to destroying the object"""
204209

205210
@property
206211
def session_path(self) -> Path | None:

0 commit comments

Comments
 (0)