I wrote the Python interface for a process-oriented task distribution system that we develop / use internally in my workplace. While fairly experienced programmers, the primary people using this interface are research scientists, not software developers, so ease of use and maximum simplification of the interface are of utmost importance as much as possible.
My library expands the sequence of entries in the sequence of brine files on a shared file server, then creates jobs that load these inputs, perform calculations, sort the results, and exit; the client script then selects the backup and creates a generator that loads and yields the results (or repeats any exception that the calculation function executes.)
This is only useful because the computational function itself is one of the serialized inputs. cPickle is pretty pleased to sort function references, but requires the pickled function to be re-ported in the same context. This is problematic. I have already solved the problem of finding the reimport module, but the vast majority of the time is a top-level function that is pickled and therefore has no path to the module. The only strategy I discovered to be able to uncover such a function on compute nodes is a nauseating little approach to modeling the source environment in which the function was pickled before scattering it:
...
The last line is the most important here - where my module picks up the function on which it should work. This code, as written, works as desired, but the direct manipulation of character tables like this is troubling.
How can I do this or something very similar to this that does not force research scientists to separate their computation scripts into the proper class structure (they use Python as the most excellent graphing calculator ever, and I would like to continue let them they will), how Pickle desperately wants it, without the unpleasant, unsafe and just scary __dict__ -and- globals() manipulations that I use above? I strongly believe that there should be a better way, but exec "from {0} import *".format("modname") did not do this, several attempts to inject the load of the brine into the targetModule link did not, but eval("commonUnpickle.load()", targetModule.__dict__, locals()) did not. All of them do not work with Unpickle AttributeError compared to the inability to find a function in <module> .
What's better?
python serialization pickle
Adam norberg
source share