It looks to me that this is what i am doin ... I really might be
doing something wrong here but can t see what.
The only difference with the livejournal's code is that i am trying to
run a blocking code so i am doing a threads.deferToThread instead of doing a 
callLater. 
To test the connection lost, client side i am disabling the wifi while
the server is blocking (sleeping). At the end of the blocking code:
request.write() and finish() are done as if the connection was available
and my ErrCallBack is not called.

I hope i am clear... in attachment the code i am using 


Thanks for your time

Seb






On Tue, May 11, 2010 at 12:54:40PM +0100, Phil Mayers wrote:
> On 11/05/10 13:23, Sebastien PASTOR wrote:
> > Thanks Phil,
> >
> > I managed to be notified when the connection is cleanly closed by the
> > client (ie: browser is stop or close window).
> > But i could not handle non-clean connection closure (ie: when wifi  goes
> > down client side for instance). request.finish() does not event raise
> > any error. ...
> > I am a bit stuck here. .. any ideas ?
> 
> I'm not sure I follow.
> 
> Have a look at this to make sure you're using it properly:
> 
> http://jcalderone.livejournal.com/50890.html
> 
> _______________________________________________
> Twisted-web mailing list
> [email protected]
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
from twisted.web import server, resource
from twisted.internet import reactor,threads
from twisted.python.util import println
from twisted.web.server import NOT_DONE_YET

class DelayedResource(resource.Resource):
    	isLeaf = True

	def _responseFinished(self,d):
		print "in response Finished ! " ,d

	def _delayedRender(self, request):
		from time import sleep
        	request.write("<html><body>Sorry to keep you waiting.</body></html>")
		request.finish()

	def error(self,err):
		print "err " , err

	def blockingError(self,err):
		print "In blocking error"

	def blockingProcess (self,request):
	 	from time import sleep
		print "Blocking ..."
		sleep(30)
		print "About to write"
		request.write("In blocking handler")
		request.finish()	
		print "wrote"


	def render_GET(self, request):
		d2=threads.deferToThread(self.blockingProcess,request)
		d2.addErrback(self.blockingError)
		d = request.notifyFinish()
		d.addErrback(self.error)
		return server.NOT_DONE_YET

site = server.Site(DelayedResource())
reactor.listenTCP(8080,site,interface="192.168.0.10")
reactor.run()
_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to