[2.2.1]How To Gracefully Shutdown an XML-RPC Server

Discussion in 'Python' started by The Jetman, Sep 27, 2003.

  1. The Jetman

    The Jetman Guest

    I'm reading source code, but I haven't found any examples of
    how to simply shutdown my XML-RPC server. I've done some nice things
    w/ it so far. I can upload and dload arbitrary files, remotely execute
    sys commands, etc. But I now want to use this code in a production
    project and essentially control a FreeBSD box from a MSOFT Access
    DB application. But the only Python fn I haven't been able to coerce
    into submission is sys.exit() !

    Here's my server method:

    def sys_Shutdown( self ):
    # don't work as is....
    sys.exit( 0 )
    return 0

    And here's what happens:

    Traceback (most recent call last):
    File "<interactive input>", line 1, in ?
    File "D:\PYTHON22\lib\xmlrpclib.py", line 821, in __call__
    return self.__send(self.__name, args)
    File "D:\PYTHON22\lib\xmlrpclib.py", line 975, in __request
    verbose=self.__verbose
    File "D:\PYTHON22\lib\xmlrpclib.py", line 853, in request
    return self.parse_response(h.getfile())
    File "D:\PYTHON22\lib\xmlrpclib.py", line 896, in parse_response
    return u.close()
    File "D:\PYTHON22\lib\xmlrpclib.py", line 571, in close
    raise apply(Fault, (), self._stack[0])
    Fault: <Fault 1: 'exceptions.SystemExit:0'>

    This is really bugging me, since I built everything else on
    my own. Any ideas ? Jet
     
    The Jetman, Sep 27, 2003
    #1
    1. Advertising

  2. The Jetman

    Andrew Dalke Guest

    Andrew Dalke, Sep 27, 2003
    #2
    1. Advertising

  3. The Jetman

    The Jetman Guest

    "Andrew Dalke" <> wrote in message news:<yx6db.4829$>...
    > The Jetman:
    > > I'm reading source code, but I haven't found any examples of
    > > how to simply shutdown my XML-RPC server.

    >
    > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114579
    >
    > Or you can ungracefully use os._exit, like pulling the emergency
    > brake on a train.
    >
    > Andrew
    >


    Andrew:

    Thanx ! I *swear* I always spend at least a couple hours or so looking
    for stuf like this on my own ! That's the single most frustrating part
    about the Web (besides this idiotic W32.Swen virus/worm) ! No matter
    how you compose a query, there's always something that you miss....

    BTW, I haven't tried it, but I bet os._exit will fail just like
    sys.exit(). Besides the reason for a graceful shutdown is more
    than cosmetic, since a forced shutdown (like a Ctrl-C) may occasionally
    leave the sockets allocated (which *has* happened.)

    Later....Jet
     
    The Jetman, Sep 28, 2003
    #3
  4. The Jetman

    Andrew Dalke Guest

    The Jetman:
    > Thanx ! I *swear* I always spend at least a couple hours or so looking
    > for stuf like this on my own !


    The Python Cookbook is an impressive collection of tidbits.

    > BTW, I haven't tried it, but I bet os._exit will fail just like
    > sys.exit().


    Unlikely. sys.exit actually raises a Python exception,
    SystemExit. This is caught by the XMLPRC server
    and converted into a message for the client.

    (And this a reason you shouldn't use "except:" in
    your code. Though if you really need it, you should
    consider
    except SystemExit:
    raise
    except:
    ...
    )

    os._exit uses the C function '_exit' which does an exit
    right away, without doing the normal cleanups that
    exit(3C) does. It doesn't raise an exception and cannot
    be overriden by other Python code. (Unless os._exit
    was replaced.)

    > Besides the reason for a graceful shutdown is more
    > than cosmetic, since a forced shutdown (like a Ctrl-C) may occasionally
    > leave the sockets allocated (which *has* happened.)


    Let me guess, you quit a server program then restarted
    it only to get a "cannot rebind to port" error message?

    Ctrl-C raises a KeyboardInterrupt exception and its
    effect should be the same as SystemExit, except for a
    couple very minor issues. It isn't the same as using
    os._exit.

    What you're seeing is a consequence of the code
    not properly handling its network resources. Eg,
    it could register an atexit handler which forces
    shut all open sockets.

    See
    http://www.manualy.sk/sock-faq/unix-socket-faq-2.html#time_wait
    for a description of what's happening at the TCP level.

    Even when that happens, it doesn't "leave the socket
    [permanently] allocated" in the system level. If you
    wait long enough, the system should release the port.

    Andrew
     
    Andrew Dalke, Sep 28, 2003
    #4
  5. The Jetman

    The Jetman Guest

    "Andrew Dalke" <> wrote in message news:<yx6db.4829$>...
    > The Jetman:
    > > I'm reading source code, but I haven't found any examples of
    > > how to simply shutdown my XML-RPC server.

    >
    > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114579
    >
    > Or you can ungracefully use os._exit, like pulling the emergency
    > brake on a train.
    >
    > Andrew
    >


    Andrew:

    Thanx ! I *swear* I always spend at least a couple hours or so looking
    for stuf like this on my own ! That's the single most frustrating part
    about the Web (besides this idiotic W32.Swen virus/worm) ! No matter
    how you compose a query, there's always something that you miss....

    BTW, I haven't tried it, but I bet os._exit will fail just like
    sys.exit(). Besides the reason for a graceful shutdown is more
    than cosmetic, since a forced shutdown (like a Ctrl-C) may occasionally
    leave the sockets allocated (which *has* happened.)

    Later....Jet
     
    The Jetman, Sep 29, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. julia
    Replies:
    6
    Views:
    484
    Sudsy
    Oct 19, 2004
  2. Pere Montolio

    XML RPC to ONC XDR RPC

    Pere Montolio, Aug 11, 2004, in forum: XML
    Replies:
    0
    Views:
    771
    Pere Montolio
    Aug 11, 2004
  3. Ymtrader
    Replies:
    1
    Views:
    615
    Adam Tauno Williams
    Mar 15, 2011
  4. Shirish Joshi

    Ruby and Sun-RPC or ONC-RPC ?

    Shirish Joshi, Apr 7, 2004, in forum: Ruby
    Replies:
    0
    Views:
    224
    Shirish Joshi
    Apr 7, 2004
  5. Vladimir Konrad

    rpc (not xml-rpc)

    Vladimir Konrad, Sep 2, 2005, in forum: Ruby
    Replies:
    5
    Views:
    153
    Austin Ziegler
    Sep 3, 2005
Loading...

Share This Page