Redirecting I/O- continuously

86 views
Skip to first unread message

Tony Cappellini

unread,
Jul 17, 2014, 5:17:15 PM7/17/14
to rpyc

Would someone point me to a better example of redirection stdio-
so that I don't need to do this?

proc = conn.modules.subprocess.Popen("ls", stdout = -1, stderr = -1)
stdout, stderr = proc.communicate()
print stdout.split()

http://rpyc.readthedocs.org/en/latest/docs/classic.html#classic

If we are running a script on another machine, having to do
stdout, stderr = proc.communicate()
print stdout.split()

is not very helpful.

Ideally, what the user experiences on the remote machine, should
be seen on the local machine.

For some reason,

proc = conn.modules.subprocess.Popen("ls", stdout = sys.stdout, stderr = sys.stdin)
causes a terrible exception.

I don't understand this

>>> proc=conn.modules.subprocess.Popen("dir",stdout=sys.stdout,stderr=sys.stderr)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\Lib\site-packages\rpyc\core\netref.py", line 196, in __call__
    return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
  File "C:\Python27\Lib\site-packages\rpyc\core\netref.py", line 71, in syncreq
    return conn.sync_request(handler, oid, *args)
  File "C:\Python27\Lib\site-packages\rpyc\core\protocol.py", line 441, in sync_request
    raise obj
AttributeError: 'file' object has no attribute '__eq__'

========= Remote Traceback (2) =========
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\rpyc\core\protocol.py", line 305, in _dispatch_request
    res = self._HANDLERS[handler](self, *args)
  File "C:\Python27\Lib\site-packages\rpyc\core\protocol.py", line 535, in _handle_call
    return self._local_objects[oid](*args, **dict(kwargs))
  File "C:\Python27\lib\subprocess.py", line 701, in __init__
    errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
  File "C:\Python27\lib\subprocess.py", line 842, in _get_handles
    elif stdout == PIPE:
  File "C:\Python27\Lib\site-packages\rpyc\core\netref.py", line 210, in method
    return syncreq(_self, consts.HANDLE_CALLATTR, name, args, kwargs)
  File "C:\Python27\Lib\site-packages\rpyc\core\netref.py", line 71, in syncreq
    return conn.sync_request(handler, oid, *args)
  File "C:\Python27\Lib\site-packages\rpyc\core\protocol.py", line 441, in sync_request
    raise obj
AttributeError: 'file' object has no attribute '__eq__'

========= Remote Traceback (1) =========
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\rpyc\core\protocol.py", line 305, in _dispatch_request
    res = self._HANDLERS[handler](self, *args)
  File "C:\Python27\Lib\site-packages\rpyc\core\protocol.py", line 547, in _handle_callattr
    return self._handle_getattr(oid, name)(*args, **dict(kwargs))
  File "C:\Python27\Lib\site-packages\rpyc\core\protocol.py", line 541, in _handle_getattr
    return self._access_attr(oid, name, (), "_rpyc_getattr", "allow_getattr", getattr)
  File "C:\Python27\Lib\site-packages\rpyc\core\protocol.py", line 507, in _access_attr
    return accessor(obj, name, *args)
AttributeError: 'file' object has no attribute '__eq__'



Tomer Filiba

unread,
Jul 20, 2014, 4:05:31 PM7/20/14
to rpyc
well, you have to put that man-in-the-middle communicate() or something similar: reading the pipes and redirecting the output to their local counterparts. btw, you might also want to check out plumbum for this use case: http://plumbum.readthedocs.org/en/latest/

as for the second version,
proc = conn.modules.subprocess.Popen("ls", stdout = sys.stdout, stderr = sys.stdin)
it won't work because rpyc can't fool the OS. internally, popen dup()s the file handles and does the necessary witchcraft for pipe redirection (which is different under windows, but still involves the OS). the objects you passed are files in the local process, but only proxies to files in the remote side. the actual error you get is meaningless, the problem is it's simply not possible.



-tomer

-----------------------------------------------------------------
    
Tomer Filiba 
tomerfiliba.com        


--

---
You received this message because you are subscribed to the Google Groups "rpyc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rpyc+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

cappy

unread,
Jul 21, 2014, 5:12:40 PM7/21/14
to rp...@googlegroups.com

Tomer,

I took that example from the Rpyc wiki, but you're telling me that it won't work.
If it won't work, why is it on the wiki? :-)

The RPYC examples seem to be inconsistent with Rpyc's capabilities.
Can we get some working examples?


>>you might also want to check out plumbum for this use case: http://plumbum.readthedocs.org/en/latest/
It doesn't seem like plumbum is right for me. I'm not making a cmd line util.

I'm just trying to run the python interpreter interactively, but remotely.
It seems like Rpyc should be able to redirect I/O from another machine, but I'm not able
to get that working yet.

Tomer Filiba

unread,
Jul 22, 2014, 1:55:11 PM7/22/14
to rpyc

You can easily redirect IO from the interpreter itself, not from a process you spawn.

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages