diff --git a/monai/deploy/core/application.py b/monai/deploy/core/application.py index 475ccfbb..759260c8 100644 --- a/monai/deploy/core/application.py +++ b/monai/deploy/core/application.py @@ -95,7 +95,7 @@ def __init__( self.path = get_class_file_path(self.__class__) # Set the runtime environment - if str(self.path).startswith(" Optional["Application"]: def get_class_file_path(cls: Type) -> Path: """Get the file path of a class. - If file path is not available, it tries to get the internal class name used in IPython(starting with ). + If the file path is not available, it tries to see each frame information + in the stack to check whether the file name ends with "interactiveshell.py" + and the function name is "run_code". + If so, it returns Path("ipython") to notify that the class is defined + inside IPython. Args: cls (Type): A class to get file path from. @@ -114,8 +118,8 @@ def get_class_file_path(cls: Type) -> Path: # If in IPython shell, use inspect.stack() to get the caller's file path stack = inspect.stack() for frame in stack: - if frame.filename.startswith("