pickle.PicklingError: Function to be pickled has free variables that are referenced before assignment in enclosing scope
The code I had that caused this problem looked like this:
| 1 | if x : | 
If this were a normal call to foo, the error instead would be:
| 1 | UnboundLocalError: local variable 'y' referenced before assignment | 
The fix is to make sure that all variables used in foo have values at the time that it is pickled:
| 1 | if x : | 
Even this would be ok:
| 1 | def foo() : |