[Twisted-Python] Re: How can I disconnect ssl connection from the client side?
johann.borck at densedata.com
Mon Feb 2 08:45:40 EST 2009
Atsuo Ishimoto wrote:
> class Client(basic.LineReceiver):
> def connectionMade(self):
> class dmyfile:
> def read(self, n):
> if CANCELED:
> return '1'
> s = basic.FileSender()
> print "start sending"
> def f1(lastChunk):
> print "finished"
> def cancel():
> print "cancel", conn.state
> global CANCELED
> CANCELED = True
I think the problem is that you call conn.disconnect before the
FileSender has a chance to call unregisterProducer on the transport (in
real life before it has sent the whole file). If the producer is not
unregistered, the doWrite() method called from the reactor doesn't even
check if the connection is in 'disconnecting' state, assumes there's
more data to come, and since no further events occur on the channel, the
connection just remains open. You can check that by manually writing one
more byte to the transport in f1, after FileSender has unregistered
itself. The correct way is to call
conn.disconnect()/transport.loseConnection() in f1 instead of in cancel.
"... If you have a producer registered, the connection won't be closed
until the producer is finished. Therefore, make sure you unregister your
producer when it's finished, or the connection willnever close ..."
> reactor.callLater(2, cancel) # disconnect 2 sec later
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
More information about the Twisted-Python