@@ -229,14 +229,14 @@ def test_send_signal(self):
229229 self .assertFalse (psutil .pid_exists (test_pid ) and name == PYTHON )
230230
231231 def test_wait (self ):
232+ # check exit code signal
232233 sproc = get_test_subprocess ()
233234 p = psutil .Process (sproc .pid )
234235 p .kill ()
235236 code = p .wait ()
236237 if os .name == 'posix' :
237238 self .assertEqual (code , signal .SIGKILL )
238239 else :
239- # windows
240240 self .assertEqual (code , 0 )
241241 self .assertFalse (p .is_running ())
242242
@@ -247,10 +247,10 @@ def test_wait(self):
247247 if os .name == 'posix' :
248248 self .assertEqual (code , signal .SIGTERM )
249249 else :
250- # windows
251250 self .assertEqual (code , 0 )
252251 self .assertFalse (p .is_running ())
253252
253+ # check sys.exit() code
254254 code = "import time, sys; time.sleep(0.01); sys.exit(5);"
255255 sproc = get_test_subprocess ([PYTHON , "-c" , code ])
256256 p = psutil .Process (sproc .pid )
@@ -266,6 +266,28 @@ def test_wait(self):
266266 self .assertEqual (p .wait (), 5 )
267267 self .assertTrue (p .wait () in (5 , None ))
268268
269+ # test timeout
270+ sproc = get_test_subprocess ()
271+ p = psutil .Process (sproc .pid )
272+ p .name
273+ self .assertRaises (psutil .TimeoutExpired , p .wait , 0.01 )
274+
275+ def test_wait_non_children (self ):
276+ # test wait() against processes which are not our children
277+ code = "import sys;"
278+ code += "from subprocess import Popen, PIPE;"
279+ code += "cmd = ['%s', '-c', 'import time; time.sleep(10)'];" % PYTHON
280+ code += "sp = Popen(cmd, stdout=PIPE);"
281+ code += "sys.stdout.write(str(sp.pid));"
282+ sproc = get_test_subprocess ([PYTHON , "-c" , code ], stdout = subprocess .PIPE )
283+
284+ grandson_pid = int (sproc .stdout .read ())
285+ grandson_proc = psutil .Process (grandson_pid )
286+ self .assertRaises (psutil .TimeoutExpired , grandson_proc .wait , 0.01 )
287+ grandson_proc .kill ()
288+ ret = grandson_proc .wait ()
289+ self .assertEqual (ret , None )
290+
269291 def test_TOTAL_PHYMEM (self ):
270292 x = psutil .TOTAL_PHYMEM
271293 self .assertTrue (isinstance (x , (int , long )))
0 commit comments