Skip to content

Commit 3f6f338

Browse files
Merge pull request #392 from KernelTuner/fix_nvml_cleanup_exception
fix issue with nvml cleanup in case of crash, issue #377
2 parents 5f0c61f + 0b14ef1 commit 3f6f338

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

kernel_tuner/observers/nvml.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ def __init__(
106106
self.use_locked_clocks = False
107107

108108
def __del__(self):
109+
try:
110+
self.restore_defaults()
111+
except ImportError:
112+
# ImportError happens when trying to reset clocks with
113+
# nvidia-smi-fallback while Python is shutting down
114+
# In this case clocks are reset using atexit, and we
115+
# can safely ignore the exception
116+
pass
117+
118+
def restore_defaults(self):
109119
# try to restore to defaults
110120
if self.pwr_limit_default is not None:
111121
self.pwr_limit = self.pwr_limit_default
@@ -210,6 +220,9 @@ def set_clocks(self, mem_clock, gr_clock):
210220
self.applications_mem_clock = mem_clock
211221

212222
# Store the fact that we have modified the clocks
223+
if not self.modified_clocks:
224+
import atexit
225+
atexit.register(self.reset_clocks)
213226
self.modified_clocks = True
214227

215228
def reset_clocks(self):

0 commit comments

Comments
 (0)