Commits

ksbuble  committed ea4f332

README.rst: Added instructions on how to use this library.
example1.py: in run_client() run threaded client and run loop indefinitely.

  • Participants
  • Parent commits 6d8c668

Comments (0)

Files changed (5)

     (ex. ["ipython", "--pylab=osx", "-c"])
 
 
+How to Use
+==========
+
+1. Comment out #import mmf on line 10 in server.py.
+2. Install asyncplot to place the libraries on your path. Go to the root asyncplot hg directory and enter this on the commandline: 
+> pip install --upgrade -e .
+3. Open two terminal windows. In the first one do this:
+> python
+>>> import example1 as e
+>>> e.run()
+
+The plot window will open.
+
+4. In the second terminal enter this:
+> python
+>>> import example1 as e
+>>> e.run_client()
+
+5. Go to the server terminal and press Enter. The plot window will animate.
+
+Note: the run_client_example() function in client.py and run_server_example() function in server.py do not work together as a running pair yet. 
+
 To Do
 =====
 

File asyncplot/client.py

                 data = self.get_data()            
                 tic = time.time()
                 v, kw = cPickle.loads(data)
-#                print("Loading pickle %g" % (time.time() - tic,))
+                print("Loading pickle %g" % (time.time() - tic,))
                 tic = time.time()
                 self.plot.draw(*v, **kw)
 #                print("Plotting %g" % (time.time() - tic,))
     r"""This version acquires the data from the server in a separate thread
     which queues the data for the plotter.
     """
-    _YEAR = 60*60*24*365
+    _YEAR = 60 * 60 * 24 * 365
+
     def __init__(self, Plotter, host=None, port=None, queue_size=1):
         Client.__init__(self, Plotter=Plotter, host=host, port=port)
         self.queue = Queue(maxsize=queue_size)
                 print("Plotting %g" % (time.time() - tic,))
         finally:
             self.is_alive = False
-            
+
             # Empty the queue to make sure that the data thread does not block
             # because of a full queue
             while not self.queue.empty():
 def run_client_example():
     #create the Client instance and pass the Plot object, then call
     #run().
-    class Plot(object):
+    class Plotter(object):
         def __init__(self):
             from matplotlib import pyplot as plt
             self.plt = plt
             plt.draw()
             #time.sleep(0.5)     # Pretend this is slow
 
-    c = Client(Plot=Plot)
+    c = Client(Plotter=Plotter)
     #raw_input('adjust plot and press return')
     c.run()
 

File asyncplot/example1.py

         plt.ion()
         plt.draw()
         time.sleep(0.5)     # Pretend this is slow
-    
+
 
 def run():
     # Create a plot instance.  This should launch the plot process, and pop up
     # the initial plot window.
     with server.Server(Plotter=Plotter, wait_for_client=True) as p:
         # Start the computation
-        x = np.linspace(0, 2*np.pi, 10)
+        x = np.linspace(0, 2 * np.pi, 10)
         dt = 0.001
         t = 0
-        for n in xrange(10000000):
-            if n % 100000 == 0:
-                print n
-            t += dt
-            y = np.sin(x - t)
-            p.update(x=x, y=y)
+        n = 0
+        max = 10000000
+        while (True):
+            if n == max:
+                n = 0
+            else:
+#                 for n in xrange(10000000):
+                if n % 100000 == 0:
+                    print n
+                    t += dt
+                    y = np.sin(x - t)
+                    p.update(x=x, y=y)
+                n = n+1
 
 
 def run_client():
     #create the Client instance and pass the Plotter object, then call run().
-    c = client.Client(Plotter=Plotter)
+#     c = client.Client(Plotter=Plotter)
+    c = client.ThreadedClient(Plotter=Plotter)
     c.run()
 
 

File asyncplot/server.py

 r"""Threaded Socket Server"""
 
+import time
 import cPickle
 import socket
 import subprocess
 import SocketServer
 import client
 
-import mmf
+# import mmf
 
 
 def get_port(port=None):
                                               # I/O??????
             )
             return client_process
-        
+
     def __enter__(self):
         self.start()
         self.client_process = self._start_client()
         return value is None
 
 
-class PlotClient(object):
+# class PlotClient(object):
+class Plotter(object):
     def __init__(self):
         from matplotlib import pyplot as plt
+
         self.plt = plt
 
     def draw(self, x, y):
         #print y
         plt.ion()
         plt.draw()
-        #time.sleep(0.5)     # Pretend this is slow
+        time.sleep(0.5)     # Pretend this is slow
 
 
-def example_server():
+def run_server_example():
     import time
     import numpy as np
-    x = np.linspace(0, 2*np.pi, 100)
+    x = np.linspace(0, 2 * np.pi, 100)
     t = 0
     dt = 0.01
     tic = time.time()
     # Ideal code:
     #with Server(client=PlotClient, wait_for_client=True) as s:
-    with Server(client_cmd=['ipython', '--pylab=osx', 'client.py'],
-                wait_for_client=True) as s:
+    #     with Server(client_cmd=['ipython', '--pylab=osx', 'client.py'],
+    #                 wait_for_client=True) as s:
+    with Server(Plotter=Plotter, wait_for_client=True) as s:
         for n in xrange(1000000):
             if n % 100000 == 0:
                 print n, time.time() - tic
             t += dt
             y = np.sin(x + t)
             s.update(x, y)
+
+if __name__ == "__main__":
+    run_server_example()

File asyncplot/threading_server.py

 r"""Server that uses threading."""
+r""" This file seems to no longer be used... as of Feb 25, 2013 """
 
 __all__ = ['Plot', 'Client', 'Server']