Comment 1 for bug 733069

Revision history for this message
Andrew Wilkins (axwalk) wrote :

I will add two new methods to pushy.client.Client: execute, and compile.

The execute method will simply be a shortcut for eval(compile(source)). e.g.:-
    conn.execute("print 123")
= conn.eval(conn.compile("print 123"))

The compile method will do two things:
 - Compile source code to a remote code object, which can be used with the remote eval builtin.
 - If given a locally defined function. will get its source (via inspect.getsource), define it in the remote interpreter, and return the function to the caller.

e.g.
    >>> print conn.compile("print 123")
    >>> <code object <module> at 0x94101d0, file "<pushy>", line 1>

e.g. (Non-interactive; inspect.getsource only works for functions defined in files.)
    def sleep(sec):
        import time
        time.sleep(sec)
    remote_sleep = conn.compile(sleep)
    remote_sleep(0.5)