ANN: generator_tools-0.1 released

Kay Schluehr kay.schluehr at gmx.net
Tue Oct 9 14:08:52 EDT 2007


On Oct 9, 7:17 pm, Steven Bethard <steven.beth... at gmail.com> wrote:
> Kay Schluehr wrote:
> > Originally I came up with the idea of a pure Python implementation for
> > copyable generators as an ActiveState Python Cookbook recipe. Too bad,
> > it was badly broken as Klaus Müller from the SimPy project pointed
> > out. Two weeks and lots of tests later I got finally a running version
> > that works not only in the very most simple use cases. As the code
> > size increased it turned out to not really fit anymore into the
> > "recipe" category and I created a package called "generator_tools".
>
> > generator_tools-0.1 is available for both Python 2.5 and Python 3.0
> > (!)
> [snip]
> >>>> pickler = GeneratorPickler("test.pkl")
> >>>> pickler.pickle_generator(g_gen)
> >>>> k_gen = pickler.unpickle_generator()
> >>>> list(g_gen) == list(k_gen)
> > True
>
> This seems like an odd syntax for pickling. Does the package support the
> normal pickle machinery?  That is, does it register the appropriate
> methods with the copy_reg module?
>
> STeVe

The picklegenerators module defines two functions: pickle_generator
that wraps the generator into a GeneratorSnapshot object and
unpickle_generator that calls copy_generator on the unpickled
GeneratorSnapshot. The only reason I also created the GeneratorPickler
class was some simplification of testing. So I didn't invest time yet
keeping the API in line with Pythons normal pickle machinery but will
do so as the project advances i.e. in the next release.

Kay




More information about the Python-list mailing list