Pushy lacks a simple remote "exec" method

Bug #733069 reported by Andrew Wilkins
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pushy
Fix Released
Wishlist
Unassigned

Bug Description

Currently to execute a non-trivial piece of code you must compile a code object and evaluate it, e.g.:-
    conn = pushy.connect(...)
    code_obj = conn.eval("compile")(source, "<filename>", "exec")
    conn.eval(code_obj, locals=..., globals=...)

This should be made simpler, by introducing a function that wraps these steps.

Related branches

Andrew Wilkins (axwalk)
Changed in pushy:
importance: Undecided → Low
importance: Low → Wishlist
status: New → Opinion
Andrew Wilkins (axwalk)
Changed in pushy:
status: Opinion → Confirmed
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)

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

An option for compiling dynamically defined functions (e.g. in an interactive session) is to manually create a "code" object in the remote interpreter, and wrap it in a types.FunctionType. I have tested this and it works. The caveat would be that the remote Python interpreter would have to support the byte code emitted by the local one, since it would/could not be recompiled from source.

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

Done. I have added "execute" and "compile" methods as described above. The compile method will attempt first to use inspect.getsource, and, failing that, will clone the code/function object in the remote interpreter.

Changed in pushy:
status: Confirmed → Fix Committed
Andrew Wilkins (axwalk)
Changed in pushy:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.