Hi,

I'm writing a Python app that uses websockets.

The default way to write an uwsgi app looks like this

def app(env, start_response):
  # do something
  return ['']


`app` is the callable and gets called for each request, in the case of
websockets, `app` runs as long as the websocket connection is open.


An almost equivalent solution is to create a callable object:


class App(object):

  def __init__(self):
    pass

  def __call__(self, env, start_response):
    # do something
    return ['']

app = App()


The problem here is in the last line. `app` is instantiated only once
and re-used for every request until the worker is restarted. How can I
make sure `app` is re-instantiated for each new request. I know about
the `--max-requests` options, and setting it to 1 seems to do the trick
(i.e. one App instance per websocket), however, I have the feeling (or
read somewhere) that this option is not really suited for production
servers. Is that true? The reason why I need a fresh `App` instance for
each new request is that my `App` objects accumulate some state during
the websocket session that needs to be reset for each new websocket session.

Any idea how I can re-instantiate a callable App-object on each request?


Cheers,

Bastian


-- 
Bastian Venthur                                      http://venthur.de
Debian Developer                                 venthur at debian org


_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to