title: Can Python pickle lambda functions?
body: <p>I have read in a number of threads that Python <code>pickle</code>/<code>cPickle</code> cannot pickle lambda functions. However the following code works, using Python 2.7.6:</p>
  
  <pre><code>import cPickle as pickle
  
  if __name__ == "__main__":
      s = pickle.dumps(lambda x, y: x+y)
      f = pickle.loads(s)
      assert f(3,4) == 7
  </code></pre>
  
  <p>So what is going on? Or, rather, what is the limit of pickling lambdas?</p>
  
  <p>[EDIT]
  I think i know why this code runs. I forgot (sorry!) i am running stackless python, which has a form of micro-threads called tasklets executing a function. These tasklets can be halted, pickled, unpickled and continued, so i guess (asked on the stackless mailing list) that it also provides a way to pickle function bodies.</p>