[Twisted-Python] Waiting for transports to close
Chris Norman
chris.norman2 at googlemail.com
Sat Dec 19 06:01:13 MST 2015
Hello,
On 17/12/2015 13:03, Glyph Lefkowitz wrote:
>
>> On Dec 17, 2015, at 4:56 AM, Chris Norman
>> <chris.norman2 at googlemail.com <mailto:chris.norman2 at googlemail.com>>
>> wrote:
>>
>> Hi,
>> It's a MUD server, so players type in commands and receive textual
>> responses.
>>
>> One of the admin commands is the ability to shutdown the server (or
>> CTRL-C might be pressed on the console). I'd like this action to
>> notify all connected transports that the server is going down for
>> shutdown, so they're not rudely disconnected, then once the
>> notifications have all gone through, then the server is free to shutdown.
>
> Gotcha. So you don't need to necessarily wait for all the messages to
> be delivered if there are slow clients waiting around; you just want
> to send everyone a farewell message and if they haven't responded
> within a reasonable timeout, go ahead and shut down anyway.
>
> If your MUD server is already a Service
> <https://twistedmatrix.com/documents/15.5.0/api/twisted.application.service.IService.html>
> being launched by twistd, you just need to add a stopService
> <https://twistedmatrix.com/documents/15.5.0/api/twisted.application.service.IService.html#stopService>
> method that returns a Deferred. When CTRL-C is hit (or anything else
> causes reactor.stop to be called), it will call this stopService
> method, and won't exit until a Deferred fires.
>
> In your case, a simple deferLater
> <https://twistedmatrix.com/documents/15.5.0/api/twisted.internet.task.html#deferLater>
> will probably do the trick. You can also speed things up when there
> are no connected clients left by cancelling that Deferred to make it
> finish firing immediately.
>
> Will that work for you?
>
>> I hope all this makes sense.
It's not a service no... Should it be? I wasn't planning to use twistd,
mainly because I don't know how to, and running
python main.py
is working fine, accepting command line arguments - the works.
It could be converted though, if there is an advantage with services?
Also, I've read quite a lot about Deferreds. I thought initially they
were for multithreading your application, but I realise that's wrong, so
I don't understand what the point in them is?
This isn't to say there isn't one mind you, I think I'm just majorly
missing the point.
>
> P.S.: For future reference, on this list the preferred style of reply
> is interleaved https://en.wikipedia.org
> <https://en.wikipedia.org/wiki/Posting_style#Interleaved_style>
Sorry, I'll do that in the future.
> /wiki/Posting_style#Interleaved_style
> <https://en.wikipedia.org/wiki/Posting_style#Interleaved_style> or
> bottom-posting: https://en.wikipedia.org/wiki/Posting_style#Bottom-posting
>
> -glyph
>
>
>
> _______________________________________________
> 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/20151219/6484d914/attachment-0002.html>
More information about the Twisted-Python
mailing list