How to gracefully shutdown on KeyboardInterrupt properly?

56 views
Skip to first unread message

Shiplu Mokaddim

unread,
Nov 5, 2017, 6:34:18 AM11/5/17
to zerorpc
Hello everyone,

I have this tiny object exposed over zerorpc.


def main():
    server = zerorpc.Server(BrokerServer(), heartbeat=(5 * 60))
    server.bind(config.LISTENNING_SOCKET)
    server.run()


I want this to be SIGINT aware. Hence I wrote it like this,


def main():
    server = zerorpc.Server(TimeslotPlanningServer(), heartbeat=(5 * 60))
    server.bind(config.LISTENNING_SOCKET)
    try:    
        server.run()
    except KeyboardInterrupt:
        # Do cleanup process
        # I clean up my server using server.killall()
        # But how do I clean up socket and everything properly?


My server launches many other clients that connect to this server.
When I receive a SIGINT ( Ctrl+C ), I disconnect those clients cleanly. 
Then I need to gracefully shutdown the server. How can I do that part?


François-Xavier Bourlet

unread,
Nov 10, 2017, 1:31:45 PM11/10/17
to zer...@googlegroups.com
Hello,

When server.run() returns, zerorpc is cleanly shutdown. Sockets should all be closed already.

Best,
fx

--
You received this message because you are subscribed to the Google Groups "zerorpc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zerorpc+u...@googlegroups.com.
To post to this group, send email to zer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zerorpc/f2f44247-3b77-4e52-ab3f-3a51109fca54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages