I want to create a “CGI script” in python that stays resident in memory and services multiple requests

StackOverflow https://stackoverflow.com/questions/1602516

  •  05-07-2019
  •  | 
  •  

Question

I have a website that right now, runs by creating static html pages from a cron job that runs nightly.

I'd like to add some search and filtering features using a CGI type script, but my script will have enough of a startup time (maybe a few seconds?) that I'd like it to stay resident and serve multiple requests.

This is a side-project I'm doing for fun, and it's not going to be super complex. I don't mind using something like Pylons, but I don't feel like I need or want an ORM layer.

What would be a reasonable approach here?

EDIT: I wanted to point out that for the load I'm expecting and processing I need to do on a request, I'm confident that a single python script in a single process could handle all requests without any slowdowns, especially since my dataset would be memory-resident.

Was it helpful?

Solution

That's exactly what WSGI is for ;)

I don't know off hand what the simplest way to turn a CGI script into a WSGI application is, though (I've always had that managed by a framework). It shouldn't be too tricky, though.

That said, An Introduction to the Python Web Server Gateway Interface (WSGI) seems to be a reasonable introduction, and you'll also want to take a look at mod_wsgi (assuming you're using Apache…)

OTHER TIPS

maybe you should direct your search towards inter process commmunication and make a search process that returns the results to the web server. This search process will be running all the time assuming you have your own server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top