[Twisted-Python] Sending disconnect messages to clients

Chris Norman chris.norman2 at googlemail.com
Tue Mar 22 14:08:40 MDT 2016


Hi Daniel,

On 22/03/2016 19:49, L. Daniel Burr wrote:
> Hi Chris,
>
> On March 22, 2016 at 2:42:14 PM, Chris Norman 
> (chris.norman2 at googlemail.com <mailto:chris.norman2 at googlemail.com>) 
> wrote:
>
>> Hi all,
>> I'm sure I asked this question before, but I can't find any answers on
>> google, and I've changed my work flow a bit now, so thought it was worth
>> re-asking.
>>
>> So on my server's protocol, I have a send method. This allows me to pass
>> arguments which get sent off to the client in the right format. The send
>> method looks something like this:
>>
>> def send(self, command, **kwargs):
>> """Cause the client to issue getattr(connection, command)(**kwargs).
>> If disconnect evaluates to True, disconnect the client after the message
>> is sent."""
>> disconnect = kwargs.get('disconnect', False)
>> try:
>> del kwargs['disconnect']
>> except KeyError:
>> pass # Argument not found.
>> d = defer.Deferred()
>> d.addCallback(self.prepare_command) Convert the command and kwargs to
>> json.
>> d.addCallback(self.deferred_write) # Write the json to the transport.
>> if disconnect:
>> d.addCallback(self.deferred_disconnect) # Issue
>> self.transport.loseConnection().
>
> You are disconnecting right here, without waiting for your Deferred to 
> fire.  It might make better sense to add the call the 
> self.transport.loseConnection() to your Deferred’s callback chain.
>
> Hope this helps,
>

Actually it's been added to the callback. I think my mail client wrapped 
the lines, but issue self.transport.LoseConnection() is the comment, so 
self.deferred_disconnect is added to the callback chain.

Sorry for the confusion.

Anything else which can cause this?

Cheers,

> Daniel
> --
> L. Daniel Burr
> ldanielburr at me.com <mailto:ldanielburr at me.com>
> (312) 656-8387
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20160322/7965ebb0/attachment-0002.html>


More information about the Twisted-Python mailing list