ValueError: Cannot pickle code objects from closures
The following code produces a strange error ValueError: Cannot pickle code objects from closures
in Sage 9.4. It does not happen at SageCell, and also disappears if I remove if set(v)&S
condition. What's wrong?
def mytestproc(n,G,S):
V = [v for v in G.vertices() if set(v)&S]
return n*len(V)
def test(n):
G = DiGraph()
return sum( val for _,val in sage.parallel.multiprocessing_sage.parallel_iter(2, mytestproc, [((n,G,S),{}) for S in Subsets(1..n)]) )
test(2)
A difference with SageMathCell might be due to different Python versions; compare the output of
import sys; print(sys.version)
.Python version 3.9.5 here and there. So, it does not explain the different behavior.
You are right. Instead, the difference can be seen by running
On my local machine this shows
sage.misc.fpickle.reduce_code
, whereas on SageMathCell it showsipykernel.codeutil.reduce_code
(which does not include the check for objects from closures). Seems fishy.