mobly
mobly copied to clipboard
Refactor: Improve subprocess timeout handling
This refactors run_command to use subprocess.Popen.communicate(timeout=...) for a more robust timeout mechanism.
The old method, relying on a custom threading.Timer, could fail to terminate stubborn processes like fastboot oem dmesg which ignore SIGTERM. The new approach uses communicate(), which sends a forceful SIGKILL on timeout, guaranteeing the process is terminated.
This change also updates the code to use the modern text argument introduced in Python 3.7 to replace universal_newlines.