Design philosophy of HTTPServer and BaseHTTPRequestHandler

T

tzuchien

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?
 
G

Gabriel Genellina

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.
 
T

tzuchien.chiu

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.

I found the server attribute in the source code (/Lib), but it is not
documented in Python Library Reference 18.19.

I wonder that if I can rely on this "undocumented" attribute?
 
G

Gabriel Genellina

En Wed, 22 Aug 2007 17:27:01 -0300, tzuchien.chiu
I found the server attribute in the source code (/Lib), but it is not
documented in Python Library Reference 18.19.

I wonder that if I can rely on this "undocumented" attribute?

It is OK to use it, it's documented under the base class,
SocketServer.RequestHandler
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top