A scalable solution for sharing objects between threads in web.py (+ flup/fcgi)

459 views Asked by At

I need to share an object between threads in web.py. I'm running a web service that performs a calculation & returns a value. The calculation is done using an object that takes up quite a lot of memory, so I don't want it to be created for each request.

I have a solution that works fine, but doesn't seem to scale:

import web
urls = ('/', 'index')

class index:
  def GET(self):
    ...
    result = web.myObject.DoCalculation()
    return result

if __name__ == "__main__":
  app = web.application(urls, globals())
  web.MyObject = LoadObjectFromFile
  app.run()

web.py automatically opens 10 threads, but this number is fixed, and it's very limiting. Can I change that?

The web.py install guide recommends using flup + a server like LightTPD, or Apache. Can this be done while retaining the shared object feature that I need? Can anyone tell me how?

I installed flup and added "fcgi" as a command line parameter when starting the server. This gave me the desired behaviour in terms of threads (unlimited number), but of course didn't perform any task. An fcgi sever needs to be defined, I think. Can this be fixed without running LightTPD, or Apache?

0

There are 0 answers