mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-13 14:57:22 +02:00
[core] plugins: Check NodePlugin
's timestamp before reloading it
When calling the `reload()` method for `NodePlugins`, we now check that the timestamp of the node's description file doesn't match with the timestamp of that same file when the `NodePlugin` was created. If it does match, then nothing happens during the `reload()`.
This commit is contained in:
parent
aa4d9ad92b
commit
424abbff82
1 changed files with 14 additions and 0 deletions
|
@ -184,6 +184,8 @@ class NodePlugin(BaseObject):
|
||||||
processEnv: the environment required for the node plugin's process. It can either
|
processEnv: the environment required for the node plugin's process. It can either
|
||||||
be specific to this node plugin, or be common for all the node plugins within
|
be specific to this node plugin, or be common for all the node plugins within
|
||||||
the plugin
|
the plugin
|
||||||
|
timestamp: the timestamp corresponding to the last time the node description's file has been
|
||||||
|
modified
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, nodeDesc: desc.Node, plugin: Plugin = None):
|
def __init__(self, nodeDesc: desc.Node, plugin: Plugin = None):
|
||||||
|
@ -199,14 +201,23 @@ class NodePlugin(BaseObject):
|
||||||
self.status = NodePluginStatus.DESC_ERROR
|
self.status = NodePluginStatus.DESC_ERROR
|
||||||
|
|
||||||
self._processEnv = None
|
self._processEnv = None
|
||||||
|
self._timestamp = os.path.getmtime(self.path)
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
""" Reload the node plugin and update its status accordingly. """
|
""" Reload the node plugin and update its status accordingly. """
|
||||||
|
if self._timestamp == os.path.getmtime(self.path):
|
||||||
|
logging.info(f"[Reload] {self.nodeDescriptor.__name__}: Not reloading. The node description "
|
||||||
|
f"at {self.path} has not been modified since the last load.")
|
||||||
|
return
|
||||||
|
|
||||||
updated = importlib.reload(sys.modules.get(self.nodeDescriptor.__module__))
|
updated = importlib.reload(sys.modules.get(self.nodeDescriptor.__module__))
|
||||||
descriptor = getattr(updated, self.nodeDescriptor.__name__)
|
descriptor = getattr(updated, self.nodeDescriptor.__name__)
|
||||||
|
self._timestamp = os.path.getmtime(self.path)
|
||||||
|
|
||||||
if not descriptor:
|
if not descriptor:
|
||||||
self.status = NodePluginStatus.ERROR
|
self.status = NodePluginStatus.ERROR
|
||||||
|
logging.error(f"[Reload] {self.nodeDescriptor.__name__}: The node description at {self.path} "
|
||||||
|
"was not found.")
|
||||||
return
|
return
|
||||||
|
|
||||||
self.nodeDescriptor = descriptor
|
self.nodeDescriptor = descriptor
|
||||||
|
@ -214,8 +225,11 @@ class NodePlugin(BaseObject):
|
||||||
|
|
||||||
if self.errors:
|
if self.errors:
|
||||||
self.status = NodePluginStatus.DESC_ERROR
|
self.status = NodePluginStatus.DESC_ERROR
|
||||||
|
logging.error(f"[Reload] {self.nodeDescriptor.__name__}: The node description at {self.path} "
|
||||||
|
"has description errors.")
|
||||||
else:
|
else:
|
||||||
self.status = NodePluginStatus.NOT_LOADED
|
self.status = NodePluginStatus.NOT_LOADED
|
||||||
|
logging.info(f"[Reload] {self.nodeDescriptor.__name__}: Successful reloading.")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def plugin(self):
|
def plugin(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue