[GRASS-git] [OSGeo/grass] 74aac0: grass.jupyter: Use weakref.finalize to manage Tem...
Vaclav Petras
noreply at github.com
Mon Feb 14 14:02:09 PST 2022
Branch: refs/heads/main
Home: https://github.com/OSGeo/grass
Commit: 74aac0a8f5247a652dbae6fe2e107c148b5721ac
https://github.com/OSGeo/grass/commit/74aac0a8f5247a652dbae6fe2e107c148b5721ac
Author: Vaclav Petras <wenzeslaus at gmail.com>
Date: 2022-02-14 (Mon, 14 Feb 2022)
Changed paths:
M python/grass/jupyter/display.py
M python/grass/jupyter/render3d.py
Log Message:
-----------
grass.jupyter: Use weakref.finalize to manage TemporaryDirectory (#2206)
Although tempfile.TemporaryDirectory uses weakref.finalize to delete the directory and its documentation does mention deletion during garbage-collection and during interpreter shutdown, the intention in its source code is that a with statement is used or explicit cleanup call is made because otherwise it generates a warning about implicit deletion. Pylint correctly generates warning suggesting with statement (consider-using-with).
In the future, we may consider implementing context-manager and cleanup method to the render classes, but even with that we need to stretch the existence of the temporary directory beyond one method, so the with statement is not applicable. For now, the classes are using only weakref.finalize which is sufficient for a notebook where the object life time is linked with the notebook's kernel life time which is relatively short. The Pylint warning is disabled and an explanatory comment is above.
More information about the grass-commit
mailing list