Forums

mediapipe makes webapp crash (Error code: 502-backend)

My website works locally and it did on pythonanywhere until I started using mediapipe. I installed it with pip3.8 install --user mediapipe as suggested on a pythonanywhere tutorial (with a console on pythonnanywhere). And until there no problem. But then whenever my website uses it, I have this error - only accessible in the server.log not in the error.log:

2022-04-19 14:32:56 !!! uWSGI process 13 got Segmentation Fault !!!
2022-04-19 14:32:56 *** backtrace of 13 ***#012PaulAndRomain PaulAndRomain.eu.pythonanywhere.com uWSGI worker 1(uwsgi_backtrace+0x2e) [0x563c6970090e]#012PaulAndRomain PaulAndRomain.eu.pythonanywhere.com uWSGI worker 1(uwsgi_segfault+0x27) [0x563c69700cf7]#012/lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7fcca888c210]#012/home/PaulAndRomain/.local/lib/python3.8/site-packages/mediapipe/python/_framework_bindings.cpython-38-x86_64-linux-gnu.so(+0xee8501) [0x7fcc78a1d501]#012/home/PaulAndRomain/.local/lib/python3.8/site-packages/mediapipe/python/_framework_bindings.cpython-38-x86_64-linux-gnu.so(_ZN4absl12lts_202103245Mutex3FerEPNS0_13base_internal14PerThreadSynchE+0x10a) [0x7fcc78a1da8a]#012/home/PaulAndRomain/.local/lib/python3.8/site-packages/mediapipe/python/_framework_bindings.cpython-38-x86_64-linux-gnu.so(_ZN4absl12lts_202103247CondVar6SignalEv+0x54) [0x7fcc78a1dcd4]#012/home/PaulAndRomain/.local/lib/python3.8/site-packages/mediapipe/python/_framework_bindings.c
2022-04-19 14:32:57 DAMN ! worker 1 (pid: 13) died, killed by signal 11 :( trying respawn ...

I have tried to uninstall mediapipe, and re-install it but it didn't help. I also tried to do everything I just did but on Python 3.9, and same things happen (if i don't install mediapipe, I have an Import Error and when I install it this bugs happen).

I've looked online and it seems several people have those errors and sometimes it was due to python versions or packages versions which is why I tried to change them but nothing helped. If any moderator or anything wants to look directly at my code, no problem, there is nothing sensible in there.

I've put prints everywhere to localize what call was responsible and it seems that calling this function: face_keypoints is the problem.

Some ML code would not work in the web apps, since it requires threading (see also: https://help.pythonanywhere.com/pages/MachineLearningInWebsiteCode/). You may check if your mediapipe code runs in a console -- if it doesn't crash, you may want to pull it out of the web app (see: https://help.pythonanywhere.com/pages/AsyncInWebApps/).