I find it extremely unlikely that you will be able to do such a service using Apache. I don’t know how mod_python works, but if it’s like any HTTP API, it’s request-based, and you have little or no control over the execution of your Python context, so Apache can thread, kill and duplicate processes at your beck and callpleasure, and in each of them instantiate a different Python context. The part you would have control of is the part that handles a single request, coming from your client.
I suggest you do a "standalone" process, run alone, and that it itself be the HTTP server. This is very easy to do with the library gevent
, for example (although it does not have very good support for Python 3, the version for Python 3 is not official).
With the very gevent
you can do asynchronous HTTP connection on other servers (gevent.httplib), or you can use this library here for more advanced features.
Usually if you do this kind of thing with Apache, the user will be occupying a thread precious of the server during all the time that runs the script, and with few requests httpd service will be completely depleted, preventing access by other users.
– Bacco