Brought picoforce driver up to speed with 0x06130001 and 0x07200000
[hooke.git] / hooke / hooke.py
index e8a00506602665605fb43193ff2bb4ad3150b805..6b4975738849b45fb0d89e3c525d5652f6e376f9 100644 (file)
 """Hooke - A force spectroscopy review & analysis tool.
 """
 
+if False: # Queue pickle error debugging code
+    """The Hooke class is passed back from the CommandEngine process
+    to the main process via a :class:`multiprocessing.queues.Queue`,
+    which uses :mod:`pickle` for serialization.  There are a number of
+    objects that are unpicklable, and the error messages are not
+    always helpful.  This block of code hooks you into the Queue's
+    _feed method so you can print out useful tidbits to help find the
+    particular object that is gumming up the pickle works.
+    """
+    import multiprocessing.queues
+    import sys
+    feed = multiprocessing.queues.Queue._feed
+    def new_feed (buffer, notempty, send, writelock, close):
+        def s(obj):
+            print 'SEND:', obj, dir(obj)
+            for a in dir(obj):
+                attr = getattr(obj, a)
+                #print '  ', a, attr, type(attr)
+            if obj.__class__.__name__ == 'Hooke':
+                # Set suspect attributes to None until you resolve the
+                # PicklingError.  Then fix whatever is breaking the
+                # pickling.
+                #obj.commands = None
+                #obj.drivers = None
+                #obj.plugins = None
+                #obj.ui = None
+                pass
+            sys.stdout.flush()
+            send(obj)
+        feed(buffer, notempty, s, writelock, close)
+    multiprocessing.queues.Queue._feed = staticmethod(new_feed)
+
 import multiprocessing
 import optparse
 import os.path
@@ -83,7 +115,7 @@ class HookeRunner (object):
         """
         ui_to_command,command_to_ui,command = self._setup_run(hooke)
         try:
-            self.ui.run(hooke.commands, ui_to_command, command_to_ui)
+            hooke.ui.run(hooke.commands, ui_to_command, command_to_ui)
         finally:
             hooke = self._cleanup_run(ui_to_command, command_to_ui, command)
         return hooke
@@ -106,7 +138,7 @@ class HookeRunner (object):
     def _setup_run(self, hooke):
         ui_to_command = multiprocessing.Queue()
         command_to_ui = multiprocessing.Queue()
-        manager = multiprocessing.Manager()        
+        manager = multiprocessing.Manager()
         command = multiprocessing.Process(name='command engine',
             target=hooke.command.run, args=(hooke, ui_to_command, command_to_ui))
         command.start()
@@ -131,9 +163,9 @@ def main():
         help='Add a command line Hooke command to run.')
     options,arguments = p.parse_args()
     if len(arguments) > 0:
-        print >> sys.stderr, 'Too many arguments to %s: %d > 0' \
-            % (sys.argv[0], len(arguments))
-        print >> sys.stderr, p.help()
+        print >> sys.stderr, 'More than 0 arguments to %s: %s' \
+            % (sys.argv[0], arguments)
+        p.print_help(sys.stderr)
         sys.exit(1)
 
     hooke = Hooke(debug=__debug__)
@@ -154,6 +186,3 @@ def main():
         hooke = runner.run(hooke)
     finally:
         hooke.close()
-
-if __name__ == '__main__':
-    main()