Simple threaded web-server based on BaseHTTPServer?

Michael Ströder michael at stroeder.com
Fri Mar 29 10:12:26 EST 2002


Aahz wrote:
 > In article <3CA36D8D.1080204 at stroeder.com>, 
=?ISO-8859-1?Q?Michael_Str=F6der?=
 > <michael at stroeder.com> wrote:
 >
 >> Aahz Maruch wrote:
 >>
 >>> In article <3C5976D0.A3A63A46 at stroeder.com>, Michael
 >>> =?iso-8859-1?Q?Str=F6der?=  <michael at stroeder.com> wrote:
 >>>
 >>>> In my case (http://web2ldap.de) I'm using threaded BaseHTTPServer but
 >>>> I'm not really happy with it. Especially since I have to use a module-wide
 >>>> lock to serialize calls into python-ldap module because the
 >>>> underlying OpenLDAP libs are not thread-safe. This can block the whole
 >>>> thing and killing threads on e.g. Linux is not possible. Having a
 >>>> single-process asyncore design would probably make things easier.
 >>>
 >>> Add another thread to serialize things instead of using a
 >>> module-wide lock.
 >>
 >> I really wonder how this helps if the call into the underlying module
 >> really blocks. BTW: In opposite to my original statement an asyncore
 >> design would also not help since the underlying OpenLDAP lib is not
 >> designed that way.
 >
 >
 > I made my suggestion in the context of assuming that your server threads
 > can continue to interact with the user while waiting for the LDAP call to
 > complete.  One possible option would be to have your server's LDAP thread
 > call out to another LDAP server that you write to fork off processes
 > (that's assuming the LDAP library is concurrent across multiple processes,
 > of course).

I apologize for not making the situation clear enough.

In fact I have a web server acting as a web gateway to the LDAP server. Each 
HTTP request is served by a thread. If a LDAP call in one HTTP server thread 
blocks forever other HTTP requests resulting in a LDAP call can't progress 
since I have to serialize all calls into the LDAP lib which is not 
thread-safe with a thread lock. IMHO a separate Queue.Queue approach does 
not help.

I already thought about having a thread lock with a timeout since I would 
assume that after e.g. 60 seconds the web client causing the blocking 
request already gave up and I would not care about the old request being 
served falsely. Does anybody have a code snippet for a thread lock with timeout?

I also thought about forking. But I work with persistent LDAP connections 
and therefore IMHO need a threaded environment.

Ciao, Michael.




More information about the Python-list mailing list