Forums

[Flask] Is the PA web server busy to all users during a single long process?

This is probably web server 101 but I'll ask anyway. One of the views on my Flask-based site has a process that can take up to a minute. When I'm running it on my local Flask test server, this ties up the server during that time, preventing access to the site from another browser session. On pythonanywhere's web server, does a long process run by one user tie up the web server for all users? My guess is no -- that it can handle multiple processes at once from different users. But I wanted to check. Thanks.

I don't work at PythonAnywhere, so don't take my word as gospel...

  1. You have a number of web workers, the exact number of which depends on how much you pay. Every web worker is going to be tied up for as long as the process takes. So, if you have one web worker, then access will be blocked while your worker thinks for a minute. If you have two or more, then you shouldn't have that problem.

  2. You probably shouldn't be using a web worker for these kind of long tasks. Have you considered using a queuing type approach, where - when a request comes in for your long running process, a message is placed in a queue and then handled by an application running on one of the console servers. You could simply have a directory called tasks, and the web worker could save there. Your console app could then monitor the directory. This would enable you to use only one web worker, and you could optimise (and monitor) your long running task much better than if it was running on a web server.

I do work for PythonAnywhere and rcs1000 has everything right. It's generally a bad idea to do long tasks in a request, mostly because your users will assume your web site is broken and go away.