Re: problems with RPYC calling subprocess.Popen

549 views
Skip to first unread message

Tomer Filiba

unread,
Jan 28, 2012, 6:47:50 AM1/28/12
to Ido, rpyc
please use the mailing list to ask questions... 

anyway, you want to run a process on a remote machine and get back its stdout/err?
just use the subprocess module, like so:

c = rpyc.classic.connect("my-other-machine")
proc = c.modules.subprocess.Popen(["/the/program", "--and", "some", "arguments"], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
stdout, stderr = proc.communicate()

you can then call proc.terminate() or kill() to terminate the program after a certain timeout.
if it's on a posix machine, you can use select(), otherwise, start a thread (see threading.Timer in the stdlib).

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



On Sat, Jan 28, 2012 at 13:31, Ido <ido2...@yahoo.com> wrote:
Hi,

I'm trying to use rpyc to run commands on remote servers.
I am interested in sending back STDOUT/ERR responses to the client, and having the option of terminating the running command after a predefined timeout. I care less if its run async or not.

My problem is that Popen has blocking reads, and will also need to be terminated manually ? (It seems that if I use rpyc.timeout, although the client times out, the popen/command continues to run on the server).

I'm not much of a python programmer, however this is my only need.
I also googled around, and tried hacking a fix myself, but was unsuccessful.

Can you please tell me what needs to be done ? (or maybe hack up a solution yourself for me :)

Toda.


Tomer Filiba

unread,
Jan 28, 2012, 7:31:29 AM1/28/12
to Ido, rpyc
communicate() is blocking. that's why i said you should start a thread or a timer or use select.


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



On Sat, Jan 28, 2012 at 14:15, Ido <ido2...@yahoo.com> wrote:
I might be wrong here, but the call to proc.communicate() would be synchronous, so I could not terminate()/kill() it with a timeout (It would wait unter .communicate would finish).

This is what seems to happen in my testing.


From: Tomer Filiba <tomer...@gmail.com>
To: Ido <ido2...@yahoo.com>
Cc: rpyc <rp...@googlegroups.com>
Sent: Saturday, 28 January 2012, 13:47
Subject: Re: problems with RPYC calling subprocess.Popen

Hemanth rao

unread,
Feb 11, 2015, 3:04:57 AM2/11/15
to rp...@googlegroups.com
I get this error message if i use the code you mentioned:

>>> proc = c.modules.subprocess.Popen(["ls"], stdin = subprocess.PIPE, stdout =
subprocess.PIPE, stderr = subprocess.PIPE)
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
WindowsError: [Error 2] The system cannot find the file specified: None

========= Remote Traceback (1) =========
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 305, in _disp
atch_request
    res = self._HANDLERS[handler](self, *args)
  File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 535, in _hand
le_call
    return self._local_objects[oid](*args, **dict(kwargs))
  File "C:\Python27\lib\subprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Reply all
Reply to author
Forward
0 new messages