How to marshal a function?

Michael Hudson mwh at python.net
Thu Nov 15 11:55:42 CET 2001


pinard at iro.umontreal.ca (François Pinard) writes:

> 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.

Well, the bytecode has changed between every released version of
Python, AFAIK.  Certainly 1.5.2->2.0, 2.0->2.1 and 2.1->2.2, and not
usually backward compatibly.

So you can forget that idea.

Cheers,
M.

-- 
  You owe The Oracle a TV with an 'intelligence' control - I've 
  tried 'brightness' but that didn't work.
                                      -- Internet Oracularity #1192-01



More information about the Python-list mailing list