Design philosophy of HTTPServer and BaseHTTPRequestHandler

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Aug 22 09:45:29 EDT 2007


On 22 ago, 06:50, "tzuchien <dot> chiu <at> gmail <dot> com"
<tzuchien.c... at gmail.com> wrote:
> Hello, everyone.
>
> Several instances of a same script, which accepts parameters and does
> a lengthy job, are executed on a remote machine. I want to couple the
> script with a tiny HTTP server so that I can connect to the machine
> with a browser and monitor the progress of jobs. The HTTP server of
> each instance will bind to different ports.
>
> A BaseHTTPRequestHandler-derived class must somehow know the
> parameters of each instance/job in order to return instance/job-
> specific result back to the client in do_GET. However, there is no way
> to pass parameters (of the lengthy job) because the constructor of
> HTTPServer expects a BaseHTTPRequestHandler-derived "class", instead
> of an "object".
>
> I cannot (or should not) dynamically create a "BaseHTTPRequestHandler-
> derived "class" for each instance of the script, right?
>
> Do I misunderstand the design philosophy of HTTPServer and
> BaseHTTPRequestHandler, and they should not be used in this way?

The server is permanent; request handler instances are created and
destroyed as HTTP requests arrive and are processed.
You should store any permanent info in the server; your
"BaseHTTPRequestHandler-derived class" can reference the server using
its "server" attribute.

--
Gabriel Genellina




More information about the Python-list mailing list