Michael Forbes  committed b22b239

Defined the desired interface in Code does not work yet.

  • Participants
  • Parent commits 0f1886a
  • Branches default

Comments (0)

Files changed (3)

 * Comprehensive testing
 * Logging (print debug messages in debug mode for checking network problems)
-* Profile performance
+* Profile performance.
 * Auto-launch client.
   * Ideally, the user can define the plotting code in a (picklable) class, and

File asyncplot/

 import numpy as np
 from matplotlib import pyplot as plt
-import threading_server
+import server
+import client
-class Plot(threading_server.Plot):
+class Plotter(object):
+    def __init__(self):
+        plt.clf()
     def draw(self, x, y):
         time.sleep(0.5)     # Pretend this is slow
-def run_server():
+def run():
     # Create a plot instance.  This should launch the plot process, and pop up
     # the initial plot window.
-    s = threading_server.Server()
-    s.start()
-    raw_input("Position plot window, and press enter to run...")
+    p = server.Server(Plotter=Plotter, wait_for_client=True)
     # Start the computation
     x = np.linspace(0, 2*np.pi, 10)
             print n
         t += dt
         y = np.sin(x - t)
-        s.update(x=x, y=y)
+        p.update(x=x, y=y)
 def run_client():
-    #create the Client instance and pass the Plot object, then call run().
-    c = threading_server.Client(Plot=Plot)
+    #create the Client instance and pass the Plotter object, then call run().
+    c = client.Client(Plotter=Plotter)
 if __name__ == "__main__":

File asyncplot/

 class PlotRequestHandler(SocketServer.BaseRequestHandler):
     def handle(self):
-        self.request.sendall(self.server.get_data())
+        self.request.sendall(self.server._get_data())
         SocketServer.TCPServer.__init__(self, (host, port),
-    def get_data(self, block=True):
+    def _get_data(self, block=True):
         r"""The object is pickled here."""
         with self.lock:
     in a subprocess.
     def __init__(self,
+                 Plotter=None,
-        client_cmd : str
-           If provided, then this command will be spawned in a subprocess (as a
-           list of commands + arguments expected by :func:``).
+        Plotter : class
+           If provided, then this class will be used to draw the plot.  It
+           should define a constructor `__init__` and a method `draw()`. The
+           constructor should open a plot window(s) so that the used can
+           position the(m) before starting the calculation.  This class must be
+           picklable (i.e. it must be defined at a top-level of an importable
+           module) , and will be called in a separate process.
         wait_for_client : Bool
            If `True`, then pause server to allow the user to adjust plot