atom feed21 messages in org.python.tutor[Tutor] sockets, files, threads
FromSent OnAttachments
Marilyn DavisJan 13, 2005 2:04 am 
Danny YooJan 13, 2005 2:31 am 
Danny YooJan 13, 2005 2:41 am 
Marilyn DavisJan 13, 2005 3:17 am 
Danny YooJan 13, 2005 6:29 am 
Alan GauldJan 13, 2005 10:20 am 
Marilyn DavisJan 15, 2005 11:19 pm 
Marilyn DavisJan 16, 2005 3:12 am 
Marilyn DavisJan 16, 2005 6:47 am 
Danny YooJan 16, 2005 7:40 am 
Marilyn DavisJan 17, 2005 5:02 am 
Danny YooJan 18, 2005 10:51 am 
Danny YooJan 18, 2005 7:24 pm 
Marilyn DavisJan 19, 2005 2:32 am 
Danny YooJan 19, 2005 8:12 am 
Kent JohnsonJan 19, 2005 12:35 pm 
Marilyn DavisJan 19, 2005 8:57 pm 
Marilyn DavisJan 19, 2005 9:13 pm 
Danny YooJan 19, 2005 9:53 pm 
Marilyn DavisJan 19, 2005 10:28 pm 
Marilyn DavisJan 21, 2005 5:05 am 
Subject:[Tutor] sockets, files, threads
From:Kent Johnson (ken@tds.net)
Date:Jan 19, 2005 12:35:49 pm
List:org.python.tutor

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()

Kent