|Marilyn Davis||Jan 13, 2005 2:04 am|
|Danny Yoo||Jan 13, 2005 2:31 am|
|Danny Yoo||Jan 13, 2005 2:41 am|
|Marilyn Davis||Jan 13, 2005 3:17 am|
|Danny Yoo||Jan 13, 2005 6:29 am|
|Alan Gauld||Jan 13, 2005 10:20 am|
|Marilyn Davis||Jan 15, 2005 11:19 pm|
|Marilyn Davis||Jan 16, 2005 3:12 am|
|Marilyn Davis||Jan 16, 2005 6:47 am|
|Danny Yoo||Jan 16, 2005 7:40 am|
|Marilyn Davis||Jan 17, 2005 5:02 am|
|Danny Yoo||Jan 18, 2005 10:51 am|
|Danny Yoo||Jan 18, 2005 7:24 pm|
|Marilyn Davis||Jan 19, 2005 2:32 am|
|Danny Yoo||Jan 19, 2005 8:12 am|
|Kent Johnson||Jan 19, 2005 12:35 pm|
|Marilyn Davis||Jan 19, 2005 8:57 pm|
|Marilyn Davis||Jan 19, 2005 9:13 pm|
|Danny Yoo||Jan 19, 2005 9:53 pm|
|Marilyn Davis||Jan 19, 2005 10:28 pm|
|Marilyn Davis||Jan 21, 2005 5:05 am|
|Subject:||[Tutor] sockets, files, threads|
|From:||Marilyn Davis (mari...@deliberate.com)|
|Date:||Jan 19, 2005 8:57:02 pm|
Thank you Kent.
On Wed, 19 Jan 2005, Kent Johnson wrote:
Marilyn Davis wrote:
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()
That makes good sense. But I'm not threading anymore and my call to server_socket.accept now blocks so I'm not sleeping. The only exceptions I want to catch now are those keyboard things, which make me stop. The socket.error I was catching was that there was no connections waiting right now. So my situation is much simpler.