few lines up, right where 'client_socket' is initialized. Like this:
### try: client_socket, client_addr = self.server_socket.accept() Spawn(client_socket).start() except socket.error, msg: time.sleep(.5) except (EOFError, KeyboardInterrupt): self.close_up() ###
Not only does this make it more clear where 'client_socket' is being used, but it ends up making the code shorter. I've dropped the 'continue' statement, as it becomes superfluous when the Spawn() moves into the try's body.
But but but, that wraps the whole thread in one try/except clause. That Spawn() call starts the thread. If a client_socket generates an error, we don't want the main thread to sleep. All the socket operations in Spawn.start() are also wrapped in their own (hopefully) intelligent try/excepts. I thought it was good practice to -not- put extra stuff in a try/except.
Use try: except: else:
The else clause is only executed if no exception happens, so the code is correct; the else is outside the scope of the try, so you don't catch unexpected exceptions.
try: client_socket, client_addr = self.server_socket.accept() except socket.error, msg: time.sleep(.5) except (EOFError, KeyboardInterrupt): self.close_up() else: Spawn(client_socket).start()
Kent
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor