(host, command, timeOut)
| 9 | rsh = "/usr/bin/rsh" |
| 10 | |
| 11 | def 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 |
no test coverage detected