embeddable Python web server (was 'derived from CGIHTTPServer.py')

Michael Ströder michael.stroeder at inka.de
Fri Feb 18 13:12:44 EST 2000

Frank Sergeant wrote:
> < Michael Ströder <michael.stroeder at inka.de> asks about an embeddable
>   Python web server>
> Well, here is what I've been using very successfully.

Thanks for submitting your code.

> Certain URLs are interpreted as calls to Python functions.

That's exactly what I'm already doing (see 0.7.0b1 on

> This allows
> persistent state as opposed to the cgi approach which would start up
> Python for each request. 

I was really surprised how much the overhead of importing the
standard modules is. My solution is quite fast now even if running
on a 486 together with the LDAP server. The next step will be to
reuse the LDAP connection objects...

> Another problem with CGIHTTPServer.py is that
> is forked a new process to handle each cgi request and fork does not
> work on Windows.

And yes, it runs under Windows now. :-)

> This module builds on SimpleHTTPServer by implementing GET and POST
> requests to run Python methods.

Ooops. I derived my class from CGIHTTPServer. It does not make a
difference in this case. But you're right: It's less over-head
sub-classing SimpleHTTPServer.SimpleHTTPRequestHandler.

> If the URL is http://somehost/cgi-bin/patlist then the method to be
> executed will be py_patlist().

Similar to my solution. But my script can also be run as normal
CGI-BIN script under the control of a "real" web server. I'm using
PATH_INFO for determining the function name.

>             if self.command == 'POST':
>                form = string.strip (self.rfile.readline())

I had problems with HTTP-POST. In my case I read the data like
module cgi does: self.rfile.read(contentlength). This works just
fine when running as a normal CGI-BIN under the control of Apache. I
tried your solution with readline() and it works now. Thanks.

But there are open issues:

SimpleHTTPServer is based on SocketServer and
[python-doc]/lib/module-SocketServer.html says:

"These four classes process requests synchronously; each request
must be completed before the next request can be started."

In my case there might be long-running LDAP queries which would
block all other users. Do you already have some example code with
threading? I will dig into this and publish the code...

Ciao, Michael.

More information about the Python-list mailing list