Commits

Miki Tebeka committed 9f05f1e

Exit without error when client closes connection

  • Participants
  • Parent commits 9316d03
  • Tags 0.1.1

Comments (0)

Files changed (1)

 from SocketServer import StreamRequestHandler, TCPServer, ThreadingMixIn
 from threading import Thread
 from traceback import print_exc
+import socket
 
 EOF = chr(4)
 
                 self.wfile.write('>>> ')
                 expr = self.rfile.readline().rstrip()
                 if expr == EOF:
-                    self.wfile.write("Bye bye\n")
                     return
                 try:
                     value = eval(expr, globals(), env)
                     self.wfile.write(format(value) + '\n')
                 except:
                     exec expr in env
-            except (EOFError, SystemExit):
-                self.wfile.write("Bye bye\n")
+            except (EOFError, SystemExit, socket.error):
                 return
             except Exception as e:
                 print_exc(file=self.wfile)
 
+    def finish(self):
+        try:
+            StreamRequestHandler.finish(self)
+        except socket.error:
+            pass
+
     def login(self):
         if not self.password:
             return True