How to marshal a function?

François Pinard pinard at iro.umontreal.ca
Wed Nov 14 21:28:55 CET 2001


Hello, my friends.

Earlier today, I wondered how to marshal a function, in view of transmitting
it to a remote machine and executing it there.  The idea was to not transmit
Python source, when the byte-compilation has already been done on this side.

I quickly found out that, for a given `function f(...) ...' I should
transmit marshal-ed `f.func_code' instead of `f'.  The resulting code
could even be eval'ed or exec'ed on the remote side, if the function
does not require arguments.  I did not saw that I could usefully return
something from the function, and surely many other properties are missing.
Moreover, the manual suggests that this is all internal things, subject
to change at any time.  The result of marshal-ing is not guaranteed to
work between Python versions, either.

So, I gave up and returned to transmitting Python sources, and am happy.
Nevertheless, I still wonder a bit if there is some clean solution to
avoid shuffling sources around, when byte code is already available, here,
and am hereby sharing this wondering with you. :-)

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list