How to create a service in Python that keeps running after responding?

3

I need to do long-pooling on a "Home" site to receive events. I then process and filter those events and I have clients that do long-pooling on me. I need to keep this in my memory, not to persist, and to provide my clients. Regardless of not having clients or having many clients doing pooling, I always need to do a single pooling on the "main" site. I want to host this in an Apache Httpd, even if some specific module is needed.

    
asked by anonymous 07.10.2014 / 16:45

1 answer

2

I find it extremely unlikely that you can do such a service using Apache. I do not know how mod_python works, but if it's like any HTTP API, it's based on requests, and you have little or no control over the execution of your Python context, and Apache can create threads, kill and duplicate processes - Pleasure, and in each of them instanciar a different Python context. The part that you would have control of is the part that deals with a single request from your client.

I suggest you do a "standalone" process that runs alone, and that it itself is the HTTP server. This is very easy to do with the gevent library, for example (although it does not has very good support for Python 3, the version for Python 3 is not official).

With gevent itself you can make asynchronous HTTP connection on other servers ( gevent.httplib ) or you can use this library here for more advanced features.

    
22.10.2014 / 13:52