[BUG] OS error when building deploy app
filipmu opened this issue · 4 comments
Describe the bug
Get an OSError: source code not available
when creating the deploy application.
OSError Traceback (most recent call last)
Cell In[6], line 1
----> 1 app = App()
File /opt/conda/lib/python3.10/site-packages/monai/deploy/core/application.py:95, in Application.__init__(self, runtime_env, do_run, path)
93 self.path = Path(path)
94 else:
---> 95 self.path = get_class_file_path(self.__class__)
97 # Set the runtime environment
98 if str(self.path) == "ipython":
File /opt/conda/lib/python3.10/site-packages/monai/deploy/utils/importutil.py:116, in get_class_file_path(cls)
100 """Get the file path of a class.
101
102 If the file path is not available, it tries to see each frame information
(...)
112 A file path of the class.
113 """
115 try:
--> 116 return Path(inspect.getfile(cls))
117 except TypeError:
118 # If in IPython shell, use inspect.stack() to get the caller's file path
119 stack = inspect.stack()
File /opt/conda/lib/python3.10/site-packages/torch/package/package_importer.py:691, in _patched_getfile(object)
689 if object.__module__ in _package_imported_modules:
690 return _package_imported_modules[object.__module__].__file__
--> 691 return _orig_getfile(object)
File /opt/conda/lib/python3.10/inspect.py:785, in getfile(object)
783 return module.__file__
784 if object.__module__ == '__main__':
--> 785 raise OSError('source code not available')
786 raise TypeError('{!r} is a built-in class'.format(object))
787 if ismethod(object):
OSError: source code not available
Steps/Code to reproduce bug
Run this notebook in jupyterlab.
Expected behavior
No stack trace, successful instantiation.
Environment details (please complete the following information)
- OS/Platform:
Linux jupyter-u63dd2b35b6fb5b--w646fbf22bc325c 5.15.0-1035-azure #42-Ubuntu SMP Tue Feb 28 19:41:23 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
- Python Version:Python 3.10.10
- Method of MONAI Deploy App SDK install: pip
- SDK Version:monai-deploy-app-sdk-0.5.0
Additional context
Thank you @filipmu for reporting the issue, and sorry for the late reply.
I tried to run the Jupyter Notebook that you provided, but I could not even go as far as you had, failing at instantiating the object, app = App()
. It is observed that the example code has only ONE operator, and in the compose
function the call to add_flow
failed for me. In this case, please change the statement to add operator only, self.add_operator(load_pil_op)
.
Also, in the example the application object was created, but its run
function was not called. So, I made the change to add operator, adding a line to call run
function with local data, app.run(input="input/AbdomenCT_007000.jpeg", output="output")
.
A line was also added to print the image array in the operator, print(f"arrry {image_arr!r}")
.
The pillow package needs to be in the requirements too, if not already installed in the virtual env.
These changes allowed me to execute the whole book without errors, and see the console output:
Going to initiate execution of operator LoadPILOperator
Executing operator LoadPILOperator (Process ID: 65396, Operator ID: bdac6aa2-0812-4fe8-880b-6d93ac872f2d)
arrry array([[101, 101, 101, ..., 101, 101, 101],
[101, 101, 101, ..., 101, 101, 101],
[101, 101, 101, ..., 101, 101, 101],
...,
[101, 101, 101, ..., 101, 101, 101],
[101, 101, 101, ..., 101, 101, 101],
[101, 101, 101, ..., 101, 101, 101]], dtype=uint8)
Done performing execution of operator LoadPILOperator
Hi @MMelQin - I made your suggested change (self.add_operator(load_pil_op)
) but still could not create the app object. Received the same error relating to ipython. My colleague suggested a fix to handle a change in python 3.10 - a change to the inspect.getfile function. Fix would be to change that line with expect (TypeError, OSError). I made the fix locally and this allowed me to create the app object with no errors.
Calling the app object resulted in an error that matched issue 410 so I downgraded typeguard~=2.12.1 and then calling it ran with no errors.
I'll submit a PR for the change.
Thanks @filipmu for the update. In my venv I have Python 3.8 and ipython 8.11.0, hence did not encounter the path issue.
It is great to get a PR from you!
Addressed in release 0.5.1