How to use _recycle_resource method in lisa

Best Python code snippet using lisa_python

process.py

Source:process.py Github

copy

Full Screen

...211 process_result.return_code,212 self._cmd,213 self._timer.elapsed(),214 )215 self._recycle_resource()216 self._log.debug(217 f"execution time: {self._timer}, exit code: {self._result.exit_code}"218 )219 if expected_exit_code is not None:220 self._result.assert_exit_code(221 expected_exit_code=expected_exit_code,222 message=expected_exit_code_failure_message,223 )224 if self._is_posix and self._sudo:225 self._result.stdout = self._filter_sudo_result(self._result.stdout)226 return self._result227 def kill(self) -> None:228 if self._process:229 self._log.debug(f"Killing process : {self._id_}")230 try:231 if self._shell.is_remote:232 # Support remote Posix so far233 self._process.send_signal(9)234 else:235 # local process should use the compiled value236 # the value is different between windows and posix237 self._process.send_signal(signal.SIGTERM)238 except Exception as identifier:239 self._log.debug(f"failed on killing process: {identifier}")240 def is_running(self) -> bool:241 if self._running and self._process:242 self._running = self._process.is_running()243 return self._running244 def wait_output(245 self,246 keyword: str,247 timeout: int = 300,248 error_on_missing: bool = True,249 interval: int = 1,250 ) -> None:251 # check if stdout buffers contain the string "keyword" to determine if252 # it is running253 start_time = time.time()254 while time.time() - start_time < timeout:255 # LogWriter only flushes if "\n" is written, so we need to flush256 # manually.257 self._stdout_writer.flush()258 # check if buffer contains the keyword259 if keyword in self._log_buffer.getvalue():260 return261 time.sleep(interval)262 if error_on_missing:263 raise LisaException(264 f"{keyword} not found in stdout after {timeout} seconds"265 )266 else:267 self._log.debug(268 f"not found '{keyword}' in {timeout} seconds, but ignore it."269 )270 def _recycle_resource(self) -> None:271 # TODO: The spur library is not very good and leaves open272 # resources (probably due to it starting the process with273 # `bufsize=0`). We need to replace it, but for now, we274 # manually close the leaks.275 if isinstance(self._process, spur.local.LocalProcess):276 popen: subprocess.Popen[str] = self._process._subprocess277 if popen.stdin:278 popen.stdin.close()279 if popen.stdout:280 popen.stdout.close()281 if popen.stderr:282 popen.stderr.close()283 elif isinstance(self._process, spur.ssh.SshProcess):284 if self._process._stdin:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful