def test_process_dies_with_object(self): """ SubProcess for a process that will never stop """ # Set up our threaded process to sleep for 1 day sp = SubProcess(['sleep', '1d']) # Now run our process sp.start() # Wait half a second (give thread time to start and run) sp.join(timeout=0.5) # We'll get the pid number of our process assert sp.pid() is not None pid = sp.pid() # Test that the process is indeed running assert self.pid_exists(pid) is True # now we'll flat out destroy the object (always abort it first) sp.abort() del sp # Test that the process is now dead as a result of the previous action assert self.pid_exists(pid) is False
def test_program_that_will_not_die(self): """ SubProcess for a process that will never stop """ # Set up our threaded process to sleep for 1 day sp = SubProcess(['sleep', '1d']) # Now run our process sp.start() # Wait half a second (give thread time to start and run) sp.join(timeout=0.5) # PID is always None unless the process is still running assert sp.pid() is not None assert isinstance(sp.pid(), int) # The process is still running assert sp.is_complete() is False # The process is not successful, but we shouldn't be relying on this # value anyway because it's not even complete. assert sp.successful() is False # time should be elapsing assert sp.elapsed() > 0.0 # No output to report at this time because one of the downsides of # using subprocess is you can't retrieve the pipes content until the # end. Thus these functions will simply return nothing. assert len(sp.stdout()) > 0 assert len(sp.stderr()) > 0 # Currently the response code is still unknown assert sp.response_code() is ReturnCode.Unknown # We'll abort the process now sp.abort() # Wait for it to complete (because it will complete now) sp.join() # PID is always None when process is stopped assert sp.pid() is None # The response code should have change to Aborted assert sp.response_code() is ReturnCode.Aborted # The process is now complete assert sp.is_complete() is True # But we should not be successful at this point assert sp.successful() is False