[Twisted-Python] [PATCH] HTTP server fix for the FD problem

Andrew Bennetts andrew-twisted at puzzling.org
Sun May 11 10:20:47 EDT 2003

On Sun, May 11, 2003 at 08:22:19AM -0500, Glyph Lefkowitz wrote:
> Hash: SHA1
> On Sunday, May 11, 2003, at 04:28 AM, Andrew Bennetts wrote:
> >I'm a little concerned that I'm being a touch to evil, though:
> >
> >-class HTTPChannel(basic.LineReceiver):
> >+class HTTPChannel(policies.TimeoutWrapper(basic.LineReceiver)):
> Yow... yes.
> I like the fact that your code is generic, but can you modify it to be 
> applied at "run-time" rather than at "compile-time"?  It seems to me 
> like it would be easier to tweak if we did that.  (Say, modify the 
> buildProtocol method of HTTPFactory...)

The existing TimeoutFactory in twisted.protocols.policies is already like
that (as are all the other policies).  This patch duplicates most of that
code, though -- I should try to spend some time to find a way to make the
same code usable both ways.  Certainly that should be done before this patch
gets checked in.

> HTTP may be enough of a special case that Moshe's patch is a good idea. 

If do that, I think it should be tweaked to use the same variables as the
TimeoutWrapper (or vice-versa) for consistency's sake, e.g. 'timeout' ->
'timeoutPeriod', and 'terminateConnection' -> 'timeoutCall'.

>  Could this code be re-used for, say, IRC?

Yep, I think the TimeoutWrapper is flexible enough to handle other protocols
cleanly; all a subclass of TimeoutWrapper(...) needs to do control timeouts
is call self.resetTimeout() and self.clearTimeout().  You can even adjust
the timeout period per-instance, if needed.  I'd love to hear if anyone can
think of any protocols this isn't sufficient for.

That said, I'm not overly attached to my implementation.  I really think
this should be generic, but if there's a less evil way to do it I'll happily
ditch this code.


More information about the Twisted-Python mailing list