Skip to content

Commit b7d58ef

Browse files
committed
Refine register and unregister functions
Signed-off-by: M Q <mingmelvinq@nvidia.com>
1 parent b6c9302 commit b7d58ef

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

monai/deploy/operators/decoder_nvimgcodec.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,33 @@ def register_as_decoder_plugin(module_path: str | None = None) -> bool:
296296
)
297297

298298
for decoder_class in SUPPORTED_DECODER_CLASSES:
299-
_logger.debug(
300-
f"Adding plugin for transfer syntax {decoder_class.UID}: "
299+
if NVIMGCODEC_PLUGIN_LABEL in decoder_class.available_plugins:
300+
_logger.debug(f"{NVIMGCODEC_PLUGIN_LABEL} already registered for transfer syntax {decoder_class.UID}.")
301+
continue
302+
303+
decoder_class.add_plugin(NVIMGCODEC_PLUGIN_LABEL, (module_path, str(func_name)))
304+
_logger.info(
305+
f"Added plugin for transfer syntax {decoder_class.UID}: "
301306
f"{NVIMGCODEC_PLUGIN_LABEL} with {func_name} in module path {module_path}."
302307
)
303-
decoder_class.add_plugin(NVIMGCODEC_PLUGIN_LABEL, (module_path, str(func_name)))
304308

305309
# Need to sort the plugins to make sure the custom plugin is the first in items() of
306310
# the decoder class search for the plugin to be used.
307311
decoder_class._available = dict(sorted(decoder_class._available.items(), key=lambda item: item[0]))
308312
_logger.debug(f"Sorted plugins for transfer syntax {decoder_class.UID}: {decoder_class._available}")
309-
_logger.info(f"Registered {NVIMGCODEC_MODULE_NAME} with {len(SUPPORTED_DECODER_CLASSES)} decoder classes.")
313+
314+
_logger.info(f"{NVIMGCODEC_MODULE_NAME} registered with {len(SUPPORTED_DECODER_CLASSES)} decoder classes.")
315+
316+
return True
317+
318+
319+
def unregister_as_decoder_plugin() -> bool:
320+
"""Unregister the decoder plugin from the supported decoder classes."""
321+
322+
for decoder_class in SUPPORTED_DECODER_CLASSES:
323+
if NVIMGCODEC_PLUGIN_LABEL in decoder_class.available_plugins:
324+
decoder_class.remove_plugin(NVIMGCODEC_PLUGIN_LABEL)
325+
_logger.info(f"Unregistered plugin for transfer syntax {decoder_class.UID}: {NVIMGCODEC_PLUGIN_LABEL}")
310326

311327
return True
312328

0 commit comments

Comments
 (0)