title: Why can't generators be pickled?
body: <p>Python's pickle (I'm talking standard Python 2.5/2.6/2.7 here) cannot pickle locks, file objects etc. </p>
  
  <p>It also cannot pickle generators and lambda expressions (or any other anonymous code), because the pickle really only stores name references.</p>
  
  <p>In case of locks and OS-dependent features, the reason <em>why</em> you cannot pickle them is obvious and makes sense.</p>
  
  <p>But <strong>why can't you pickle generators?</strong></p>
  
  <hr>
  
  <p><em>Note</em>: just for clarity -- I'm interested in the fundamental reason (or assumptions and choices that went into that design decision) <em>why</em>, not in "because it gives you a Pickle error". </p>
  
  <p>I realize the question's a bit wide-aimed, so here's a rule of thumb of whether your answered it: "If these assumptions were raised, or the type of allowed generator somehow more restricted, would pickling generators work again?"</p>