Wednesday, October 29, 2014

Decoration, Pickle, Closure.

What is closure? What it has to do with pickle-able ? 

A closure occurs when a function has access to a local variable from an enclosing scope that has finished its execution.
Here is an example, test2 doesn't work because pickle works with name. test3 doesn't work because it conflicts with top-level function 'foo'



Pickle, Decorator. 

The decorated function has the same name as the original function, makes it un-pickle-able.

the right way to write a decorator function is to always use 'wraps'. Be able to pickled is crucial when you programming multiprocess.


No comments:

Post a Comment