Michael Forbes avatar Michael Forbes committed ecad6d2

Server works, but breaking (or adding set_trace()) does not release the socket

Comments (0)

Files changed (1)

asyncplot/server.py

 r"""Threaded Socket Server"""
 
 import cPickle
-#import socket
+import socket
 import threading
 import SocketServer
 
+import mmf
+
 
 class PlotRequestHandler(SocketServer.BaseRequestHandler):
     def handle(self):
         self.request.sendall(self.server.get_data())
+        #self.request.shutdown(socket.SHUT_RDWR)
+        #self.request.close()
 
 
 class PlotSocketServer(SocketServer.ThreadingMixIn,
         self.lock = threading.Lock()  # RLock()??
         self.have_data = threading.Event()
         self.data = None
+        
+        self.daemon_threads = True       # Don't keep python alive.
+        self.allow_reuse_address = True  # Allow port reuse after termination.
         SocketServer.TCPServer.__init__(self, (host, port),
                                         PlotRequestHandler)
-        #super(PlotSocketServer, self).__init__((host, port),
-        #                                       PlotRequestHandler)
 
     def get_data(self, block=True):
         r"""The object is pickled here."""
                  port=PlotSocketServer._PORT):
         self.server = PlotSocketServer(host=host, port=port)
         threading.Thread.__init__(self, target=self.server.serve_forever)
-        self.daemon = True      # Don't keep python alive.
+        self.daemon = True               # Don't keep python alive.
 
     def __enter__(self):
+        #mmf.mdb()
         self.start()
         return self.server
 
     def __exit__(self, type, value, traceback):
+        #mmf.mdb()
         self.server.shutdown()
         return value is None
 
     dt = 0.01
     tic = time.time()
     with Server() as s:
-        for n in xrange(1000000):
+        for n in xrange(100000):
             if n % 100000 == 0:
                 print n, time.time() - tic
                 tic = time.time()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.