Forums

504 Gateway timeout on time-consuming backend function

Hello, I am pretty new to pythonAnywhere and ran into this problem. I have an app that needs to initialize the variables first on backend before running app frontend. This is a one-time process. During the init phase we load 3 big files (indices) into app memory which on localhost take over 10 minutes. Obviously this causes 504 Gateway Time-out error on host. Could you please suggest the workaround or the proper approach to deployment of such app on pythonanywhere? Thank you :)

Unfortunately I think you'd need to do some re-architecture to get that working on PythonAnywhere; website worker processes are pretty ephemeral on our architecture, and might be stopped and started at any time. What do you need to load so much data in for? Perhaps there's some way to achieve the same goal without such a heavyweight startup procedure.

Thanks for reply. These are basically local index files for LLM to create a local knowledge repository. This works well with smaller files (provided that they are loaded within a time limit). I am experimenting now with different sets.of larger files. If you have any architectural ideas, please let me know.

Perhaps that's something you can offload to a database?

Consider loading large files asynchronously or in a separate initialization script to avoid 504 errors on PythonAnywhere during app startup.