"""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
"""
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
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()
Removing lots of curves one at a time can be tedious. With this
command you can use a function `filter` to select the curves you
wish to keep.
+
+ Notes
+ -----
+ There are issues with pickling functions bound to class
+ attributes, because the pickle module doesn't know where those
+ functions were originally defined (where it should point the
+ loader). Because of this, subclasses with hard-coded filter
+ functions are encouraged to define their filter function as a
+ method of their subclass. See, for example,
+ :meth:`NoteFilterCommand.filter`.
"""
- def __init__(self, plugin, name='filter playlist', filter_fn=None):
+ def __init__(self, plugin, name='filter playlist'):
super(FilterCommand, self).__init__(
name=name,
arguments=[
PlaylistNameArgument,
],
help=self.__doc__, plugin=plugin)
- self.filter_fn = filter_fn
- if filter_fn == None:
+ if not hasattr(self, 'filter'):
self.arguments.append(
Argument(name='filter', type='function', optional=False,
help="""
""".strip()))
def _run(self, hooke, inqueue, outqueue, params):
- if self.filter_fn == None:
+ if not hasattr(self, 'filter'):
filter_fn = params['filter']
else:
- filter_fn = self.filter_fn
+ filter_fn = self.filter
p = params['playlist'].filter(filter_fn,
hooke=hooke, inqueue=inqueue, outqueue=outqueue, params=params)
hooke.playlists.add(p)
"""
def __init__(self, plugin):
super(NoteFilterCommand, self).__init__(
- plugin, name='note filter playlist',
- filter_fn=lambda curve, hooke, inqueue, outqueue, params : \
- 'note' in curve.info and curve.info['note'] != None)
+ plugin, name='note filter playlist')
+
+ def filter(self, curve, hooke, inqueue, outqueue, params):
+ return 'note' in curve.info and curve.info['note'] != None