kr-prince / fitness_trainer

Code for virtual fitness trainer application developed as part of capstone project for PGDAIML course - Univ of Hyderabad and AppliedRoots.
MIT License
3 stars 2 forks source link

TypeError: cannot pickle 'module' object #1

Open KalaiKumarR opened 2 years ago

KalaiKumarR commented 2 years ago

Getting error when I try to run 'streamlit run app.py'

TypeError: cannot pickle 'module' object

Traceback: File "c:\users\kalaikumar\anaconda3\envs\virtualfit\lib\site-packages\streamlit\script_runner.py", line 354, in _run_script exec(code, module.__dict__) File "C:\Users\kalaikumar\Downloads\fitness_trainer-main\fitness_trainer-main\app\app.py", line 95, in <module> main() File "C:\Users\kalaikumar\Downloads\fitness_trainer-main\fitness_trainer-main\app\app.py", line 43, in main me = MainEngine() File "C:\Users\kalaikumar\Downloads\fitness_trainer-main\fitness_trainer-main\app\main_engine.py", line 21, in __init__ self.run() File "C:\Users\kalaikumar\Downloads\fitness_trainer-main\fitness_trainer-main\app\utils\worker.py", line 30, in run self.proc.start() File "c:\users\kalaikumar\anaconda3\envs\virtualfit\lib\multiprocessing\process.py", line 121, in start self._popen = self._Popen(self) File "c:\users\kalaikumar\anaconda3\envs\virtualfit\lib\multiprocessing\context.py", line 224, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "c:\users\kalaikumar\anaconda3\envs\virtualfit\lib\multiprocessing\context.py", line 327, in _Popen return Popen(process_obj) File "c:\users\kalaikumar\anaconda3\envs\virtualfit\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__ reduction.dump(process_obj, to_child) File "c:\users\kalaikumar\anaconda3\envs\virtualfit\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj)

kr-prince commented 2 years ago

Hi @KalaiKumarR Kindly help me reproduce the issue you are facing with some more details. Please make sure you have:

KalaiKumarR commented 2 years ago

I have also done the same Downloaded the anaconda -> Downloaded the repo and extracted -> opened the anaconda prompt -> nevigated to the repo -> conda env create -f environment.yml -> conda activate virtualFit -> streamlit run app.py -> Getting the below mentioned error. I am not sure why? May be it asking for the streamlit argument. My python version 3.9.7

Error: (base) C:\Users\kalaikumar.rajan\Downloads\fitness_trainer-main\fitness_trainer-main\app>python --version Python 3.9.7

(base) C:\Users\kalaikumar.rajan\Downloads\fitness_trainer-main\fitness_trainer-main\app>conda activate virtualFit

(virtualFit) C:\Users\kalaikumar.rajan\Downloads\fitness_trainer-main\fitness_trainer-main\app>streamlit run app.py

You can now view your Streamlit app in your browser.

Local URL: http://localhost:8501 Network URL: http://10.93.46.61:8501

2022-04-11 09:35:57.113 Traceback (most recent call last): File "c:\users\kalaikumar.rajan\anaconda3\envs\virtualfit\lib\site-packages\streamlit\script_runner.py", line 354, in _run_script exec(code, module.dict) File "C:\Users\kalaikumar.rajan\Downloads\fitness_trainer-main\fitness_trainer-main\app\app.py", line 95, in main() File "C:\Users\kalaikumar.rajan\Downloads\fitness_trainer-main\fitness_trainer-main\app\app.py", line 43, in main me = MainEngine() File "C:\Users\kalaikumar.rajan\Downloads\fitness_trainer-main\fitness_trainer-main\app\main_engine.py", line 21, in init self.run() File "C:\Users\kalaikumar.rajan\Downloads\fitness_trainer-main\fitness_trainer-main\app\utils\worker.py", line 30, in run self.proc.start() File "c:\users\kalaikumar.rajan\anaconda3\envs\virtualfit\lib\multiprocessing\process.py", line 121, in start self._popen = self._Popen(self) File "c:\users\kalaikumar.rajan\anaconda3\envs\virtualfit\lib\multiprocessing\context.py", line 224, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "c:\users\kalaikumar.rajan\anaconda3\envs\virtualfit\lib\multiprocessing\context.py", line 327, in _Popen return Popen(process_obj) File "c:\users\kalaikumar.rajan\anaconda3\envs\virtualfit\lib\multiprocessing\popen_spawn_win32.py", line 93, in init reduction.dump(process_obj, to_child) File "c:\users\kalaikumar.rajan\anaconda3\envs\virtualfit\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj) TypeError: cannot pickle 'module' object

Traceback (most recent call last): File "", line 1, in File "c:\users\kalaikumar.rajan\anaconda3\envs\virtualfit\lib\multiprocessing\spawn.py", line 107, in spawn_main new_handle = reduction.duplicate(pipe_handle, File "c:\users\kalaikumar.rajan\anaconda3\envs\virtualfit\lib\multiprocessing\reduction.py", line 79, in duplicate return _winapi.DuplicateHandle( OSError: [WinError 6] The handle is invalid 2022-04-11 09:35:59.787 WARNING root: ←[33m←[1mWarning:←[0m to view a Streamlit app on a browser, use Streamlit in a file and run it with the following command:

_streamlit run [FILE_NAME] [ARGUMENTS]_

2022-04-11 09:35:59.787 WARNING streamlit.state.session_state: Session state does not function when running a script without streamlit run

KalaiKumarR commented 2 years ago

hi @kr-prince can you help me out? to resolve this issue

kr-prince commented 2 years ago

Hi, @KalaiKumarR I have a Ubuntu 20.04.4 LTS system. I re-did all the steps from scratch. It works fine. I am trying to recreate this on a windows system. Will get back to you.

kr-prince commented 2 years ago

Hi, @KalaiKumarR I was able to recreate this issue on a windows system. The problem is, multiprocessing uses different approaches while starting a new process in Windows(spawn) and Unix(fork).

The error we are getting is because the required objects have to be serialized and shared, which is okay if the process is simple and requires basic functions and inbuilt data structures, but becomes a huge problem if the run method is handling more complex requirements and sharing complex objects(our case). fork is not available in Windows. I tried to find a solution for this, or a workaround for Windows but haven't been successful so far. Please refer the below links: multiprocessing-fork-vs-spawn Python official docs - multiprocessing

I kind of knew multi-processing was not the best system design for this application, but was focused more on the data science aspect. Now will have to re-think on the system design aspect. Feel free to share/contribute if you find out something.