[Twisted-Python] Re: [Twisted-commits] r16103 - Make loopbackTCP and loopbackUNIX return Deferreds
Jonathan Lange
jml at mumak.net
Tue Feb 28 13:42:05 MST 2006
On 3/1/06, Jean-Paul Calderone <exarkun at divmod.com> wrote:
> On Tue, 28 Feb 2006 05:37:54 -0700, Jonathan Lange <jml at wolfwood.twistedmatrix.com> wrote:
> >Author: jml
> >Date: Tue Feb 28 05:37:52 2006
> >New Revision: 16103
> >
> >Modified:
> > branches/deprecated-trial-1509/twisted/mail/test/test_imap.py
> > branches/deprecated-trial-1509/twisted/mail/test/test_pop3.py
> > branches/deprecated-trial-1509/twisted/mail/test/test_pop3client.py
> > branches/deprecated-trial-1509/twisted/mail/test/test_smtp.py
> > branches/deprecated-trial-1509/twisted/protocols/loopback.py
> > branches/deprecated-trial-1509/twisted/test/test_loopback.py
> > branches/deprecated-trial-1509/twisted/test/test_tpfile.py
> >Log:
> >Make loopbackTCP and loopbackUNIX return Deferreds
> >
> >Modified: branches/deprecated-trial-1509/twisted/protocols/loopback.py
> >==============================================================================
> >--- branches/deprecated-trial-1509/twisted/protocols/loopback.py (original)
> >+++ branches/deprecated-trial-1509/twisted/protocols/loopback.py Tue Feb 28 05:37:52 2006
> >@@ -122,14 +123,9 @@
> > clientF.noisy = noisy
> > reactor.connectTCP('127.0.0.1', serverPort.getHost().port, clientF)
> >
> >- # this needs to wait until:
> >- # A: the client has disconnected
> >- # B: the server has noticed, and its own socket has disconnected
> >- # C: the listening socket has been shut down
> >- spinUntil(lambda :clientF.disconnected) # A
> >- spinUntil(lambda :not server.transport.connected) # B
> >- serverPort.stopListening()
> >- spinUntil(lambda :not serverPort.connected) # C
> >+ d = clientF.deferred
> >+ d.addCallback(lambda x : defer.maybeDeferred(serverPort.stopListening))
> >+ return d
> >
>
> This now has a race, where the Deferred may fire before the server protocol is notified that the connection has been lost.
Awesome, I wondered what that other thing was for.
How do I get a Deferred to fire when a transport is disconnected?
jml
More information about the Twisted-Python
mailing list