Skip to content

Commit feb3536

Browse files
committed
Avoid leaving the init finalizer around
1 parent c4257df commit feb3536

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/lmstudio/_ws_impl.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,15 @@ def call_in_background(self, func: Callable[[], Any]) -> None:
288288
# Creating this finalizer here ensures the weakref finalization hook is
289289
# registered at import time, and hence runs *after* any such hooks
290290
# (assuming the lmstudio SDK is imported before the hooks are registered)
291-
weakref.finalize(list, int)
291+
def _register_weakref_atexit_hook() -> None:
292+
class C:
293+
pass
294+
295+
weakref.finalize(C(), int)
296+
297+
298+
_register_weakref_atexit_hook()
299+
del _register_weakref_atexit_hook
292300

293301

294302
class AsyncWebsocketThread(BackgroundThread):

0 commit comments

Comments
 (0)