4 ms·
Would you suggest pickle or a more generic compressed JSON?
by iandanforth 15y ago
Would you suggest pickle or a more generic compressed JSON?
- munin 15y agopickle can't represent functions. pickle is higher level and (I theorize) its authors realized the quandary you can work yourself into with function serialization. you could use pickle, you would just have to have a more complicated client installation.. additionally, since clients are directly executing code that the server provides, it might be nice (in the finished product, of course) to see some validation of the code blobs before executing them.
- michaelfairley 15y agoUnfortunately, python doesn't let you serialize a function through pickle or other non-marshal serializations. The only cross-python solution is to actually have python read the source code and send it (rather than the bytecode) over the wire, which seems much more brittle to me. See http://stackoverflow.com/questions/1253528/is-there-an-easy-way-to-pickle-a-python-function-or-otherwise-serialize-its-code http://stackoverflow.com/questions/1253528/is-there-an-easy-...
- munin 15y agooh yeah, if you run this script with different python versions, you will experience mysterious failures probably. in some limited testing I did, I was able to serialize a function on 64-bit Linux and have it execute on 32-bit Windows. I even went crazy and wrote using ctypes against the Win32 API on Linux and sent a string to be loads()ed by code on Windows... and that worked. (this isn't really python being awesome as much as bytecode languages working as designed... but as far as I know this is all working by happy co-incidence, unlike say Java, where the bytecode is designed to be cross-platform...)