MCPcopy Create free account
hub / github.com/ActiveState/code / rshTimed

Function rshTimed

recipes/Python/577390_RSH_with_timeout/recipe-577390.py:11–32  ·  view source on GitHub ↗
(host, command, timeOut)

Source from the content-addressed store, hash-verified

9rsh = "/usr/bin/rsh"
10
11def rshTimed(host, command, timeOut):
12 rshD = subprocess.Popen([rsh,host,command],stdout=sys.stdout,stderr=sys.stdout)
13 timeStart = time.time()
14 if(timeOut != 0):
15 while(1):
16 # Check if timeOut secs have passed since the execution of rsh
17 if(int(time.time() - timeStart) > int(timeOut)):
18 # Kill the process if timed out
19 rshD.kill()
20 break
21 # Check if the execution of rsh is done before the timeOut value
22 elif(rshD.poll() == 0):
23 break
24 # Sleep for a sec before the next loop.
25 time.sleep(1)
26 try:
27 # If rsh is killed then reap it
28 eStatus = os.waitpid(rshD.pid, 0)[1]
29 except:
30 # If rsh has been completed successfully
31 eStatus = rshD.returncode
32 return(eStatus)
33
34
35

Callers 1

recipe-577390.pyFile · 0.85

Calls 4

timeMethod · 0.45
killMethod · 0.45
pollMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected