SocketServer.ThreadingTCPServer accepts clients outside server_forever

Discussion in 'Python' started by Okko Willeboordse, Nov 9, 2008.

  1. Hello,

    SocketServer.ThreadingTCPServer accepts connections (clients can
    connect) before and after it's server_forever method is called,
    see below for an example.

    IMHO it should only accept connections while server_forever is
    running.

    Kind regards,

    Okko

    Example, both _socket.connect calls should throw;

    import SocketServer
    import threading
    import time
    import socket

    server = SocketServer.ThreadingTCPServer(("127.0.0.1", 12345),
    SocketServer.BaseRequestHandler)

    _socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    _socket.connect(("127.0.0.1", 12345))

    def shutdown_server():
    while not server._BaseServer__serving:
    time.sleep(0.1)
    server.shutdown()

    thread = threading.Thread(target = shutdown_server)
    thread.start()

    server.serve_forever()
    thread.join()

    _socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    _socket.connect(("127.0.0.1", 12345))
     
    Okko Willeboordse, Nov 9, 2008
    #1
    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. UrgeOverkill
    Replies:
    2
    Views:
    460
    Peter Hansen
    Feb 19, 2004
  2. Francesco
    Replies:
    1
    Views:
    542
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Dec 27, 2006
  3. Stuart D. Gathman

    Debugging SocketServer.ThreadingTCPServer

    Stuart D. Gathman, Jan 16, 2007, in forum: Python
    Replies:
    0
    Views:
    337
    Stuart D. Gathman
    Jan 16, 2007
  4. Jean-Paul Calderone

    Re: Debugging SocketServer.ThreadingTCPServer

    Jean-Paul Calderone, Jan 16, 2007, in forum: Python
    Replies:
    2
    Views:
    397
    R. Bernstein
    Feb 4, 2007
  5. Brad Brock
    Replies:
    0
    Views:
    347
    Brad Brock
    May 19, 2007
Loading...

Share This Page