Killing a socket server in DOS?

Steve Holden sholden at holdenweb.com
Fri May 31 05:40:52 EDT 2002


"Magnus Lie Hetland" <mlh at vier.idi.ntnu.no> wrote ...
> I've written a simple server using asyncore.dispatcher as a
> superclass; in UNIX I don't ave any problems with it, but in DOS it
> seems I can't kill the asyncore.loop() loop with Ctrl-Z or Ctrl-C or
> Ctrl-D or anything... Is there a way? Should I implement it
> differently? (I could always add functionality for killing it through
> the protocol itself, but that seems a bit unnecessary...)
>

Here's a snippet using asyncore that seems to do what you want. Are you
saying that you can't trap KeyboiardInterrupt? You'll have your own
http_server() equivalent already, I'm guessing.

def serve():

    port = 8080

    if len(sys.argv) >1:
        try:
            port = int(sys.argv[1])
        except:
            sys.exit("Illegal port number")

    logfile = open(LOGFILE, "a")
    server = http_server('', port, logfile)
    try:
        asyncore.loop(1.0) # Frequent checks for interrupt
    except KeyboardInterrupt:
        print "Completed" # on console
        logfile.close()


regards
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list