[Twisted-Python] connectionLost patch
Chris Armstrong
carmstro at twistedmatrix.com
Thu Sep 27 13:54:09 EDT 2001
oops. I swear I tested this thing. That "StringIO()" should be
"StringIO.StringIO()". bitrot from tuesday. =)
On Thu, Sep 27, 2001 at 12:40:55PM -0500, Chris Armstrong wrote:
> I patched connectionLost in server.request to call 'connectionLost' on
> resources if they have it. This is not a very good patch, and a bad
> solution, I think, but redoz wanted it for some functionality he needed
> in a streaming chat web thingy.
>
> Any ideas on a better solution for disconnect notification? should this just
> stay a third party feature?
>
>
> Index: server.py
> ===================================================================
> RCS file: /cvs/Twisted/twisted/web/server.py,v
> retrieving revision 1.16
> diff -u -r1.16 server.py
> --- server.py 2001/09/08 11:08:13 1.16
> +++ server.py 2001/09/25 20:52:10
> @@ -144,6 +144,20 @@
>
> _host = socket.gethostbyaddr(socket.gethostname())[0]
>
> + def connectionLost(self):
> + log.msg("%s's connection was lost" % self)
> + try:
> + self.prepath = []
> + self.postpath = string.split(self.path[1:], '/')
> + resrc = self.site.getResourceFor(self)
> + if hasattr(resrc, "connectionLost"):
> + resrc.connectionLost(self)
> + except:
> + io = StringIO()
> + traceback.print_exc(file=io)
> + log.msg("Unkown error during connectionLost :-(\n%s" % io.getvalue())
> + http.HTTP.connectionLost(self)
> +
> def process(self):
> "Process a request."
> # Log the request to a file.
More information about the Twisted-Python
mailing list