lordmauve / chopsticks

Chopsticks is an orchestration library: it lets you execute Python code on remote hosts over SSH.
https://chopsticks.readthedocs.io/
Apache License 2.0
158 stars 16 forks source link

Error when trying to print env #46

Closed postrational closed 7 years ago

postrational commented 7 years ago

I'm having a problem running this simple function on a remote host:

import os
def print_env():
    print(os.environ)

The following is a copy of my terminal session:

Python 3.5.1 (default, Apr 18 2016, 11:46:32)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from chopsticks.tunnel import Tunnel
   ...: tun = Tunnel(host='my.remote.host', user='my_user_name')
   ...:

In [2]: import time
   ...: print('Time on %s:' % tun.host, tun.call(time.time))
   ...:

Time on my.remote.host: 1499942192.4012492

In [3]:

In [3]: import os
   ...: def print_env():
   ...:     print(os.environ)
   ...:

In [4]: print_env()
   ...:
environ({'LC_CTYPE': 'UTF-8', 'COMMAND_MODE': 'unix2003', 'Apple_PubSub_Socket_Render': '/private/tmp/com.apple.launchd.P6DZWedA1U/Render', 'LANG': 'en_US.utf-8', ... 'TERM_PROGRAM': 'iTerm.app'})

In [5]: tun.call(print_env)
   ...:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-5ef9d5c918df> in <module>()
----> 1 tun.call(print_env)

/Users/my_user_name/.virtualenvs/default/lib/python3.5/site-packages/chopsticks/tunnel.py in call(self, callable, *args, **kwargs)
    286         """
    287         self.connect()
--> 288         self._call_async(loop.stop, callable, *args, **kwargs)
    289         ret = self._run_loop()
    290         if isinstance(ret, ErrorResult):

/Users/my_user_name/.virtualenvs/default/lib/python3.5/site-packages/chopsticks/tunnel.py in _call_async(self, on_result, callable, *args, **kwargs)
    295         id = self._next_id()
    296         self.callbacks[id] = on_result
--> 297         params = prepare_callable(callable, args, kwargs)
    298         self.reader.start()
    299         self.write_msg(

/Users/my_user_name/.virtualenvs/default/lib/python3.5/site-packages/chopsticks/serialise_main.py in prepare_callable(func, args, kwargs)
    124     """Prepare a callable to be called even if it is defined in __main__."""
    125     if isinstance(func, types.FunctionType) and func.__module__ == '__main__':
--> 126         func_data = serialise_func(func)
    127         return execute_func, (func_data,) + args, kwargs
    128     return func, args, kwargs

/Users/my_user_name/.virtualenvs/default/lib/python3.5/site-packages/chopsticks/serialise_main.py in serialise_func(f, seen)
     60     # expressions
     61     code = compile(source, '<main>', 'exec')
---> 62     names = trace_globals(code)
     63
     64     imported_names = {}

/Users/my_user_name/.virtualenvs/default/lib/python3.5/site-packages/chopsticks/serialise_main.py in trace_globals(code)
     14     global_ops = (LOAD_GLOBAL, LOAD_NAME)
     15     loads = set()
---> 16     for op, arg in iter_opcodes(code.co_code):
     17         if op in global_ops:
     18             loads.add(code.co_names[arg])

/Users/my_user_name/.virtualenvs/default/lib/python3.5/site-packages/chopsticks/serialise_main.py in iter_opcodes(code)
     31     if sys.version_info >= (3, 4):
     32         # Py3 has a function for this
---> 33         for _, op, arg in dis._unpack_opargs(code):
     34             yield (op, arg)
     35         return

AttributeError: module 'dis' has no attribute '_unpack_opargs'
lordmauve commented 7 years ago

This is a duplicate of issue #40, which is fixed on master. Please try again with the master branch of Chopsticks and re-open that issue if this still occurs.

lordmauve commented 7 years ago

I should also say that printing to stdout on a remote host will go to /dev/null. You can, however, see output printed to stderr.