mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-28 19:58:45 +00:00
fix(python): runaway emulator process
[no changelog]
This commit is contained in:
parent
e4ed101d01
commit
b765cb1e2c
@ -14,6 +14,7 @@
|
|||||||
# You should have received a copy of the License along with this library.
|
# You should have received a copy of the License along with this library.
|
||||||
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||||
|
|
||||||
|
import atexit
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -27,6 +28,15 @@ from ..transport.udp import UdpTransport
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
EMULATOR_WAIT_TIME = 60
|
EMULATOR_WAIT_TIME = 60
|
||||||
|
_RUNNING_PIDS = set()
|
||||||
|
|
||||||
|
|
||||||
|
def _cleanup_pids():
|
||||||
|
for process in _RUNNING_PIDS:
|
||||||
|
process.kill()
|
||||||
|
|
||||||
|
|
||||||
|
atexit.register(_cleanup_pids)
|
||||||
|
|
||||||
|
|
||||||
def _rm_f(path: Path) -> None:
|
def _rm_f(path: Path) -> None:
|
||||||
@ -130,6 +140,7 @@ class Emulator:
|
|||||||
def wait(self, timeout: Optional[float] = None) -> int:
|
def wait(self, timeout: Optional[float] = None) -> int:
|
||||||
assert self.process is not None, "Emulator not started"
|
assert self.process is not None, "Emulator not started"
|
||||||
ret = self.process.wait(timeout=timeout)
|
ret = self.process.wait(timeout=timeout)
|
||||||
|
_RUNNING_PIDS.remove(self.process)
|
||||||
self.process = None
|
self.process = None
|
||||||
self.stop()
|
self.stop()
|
||||||
return ret
|
return ret
|
||||||
@ -164,6 +175,7 @@ class Emulator:
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.process = self.launch_process()
|
self.process = self.launch_process()
|
||||||
|
_RUNNING_PIDS.add(self.process)
|
||||||
try:
|
try:
|
||||||
self.wait_until_ready()
|
self.wait_until_ready()
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
@ -197,6 +209,7 @@ class Emulator:
|
|||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
LOG.info("Emulator seems stuck. Sending kill signal.")
|
LOG.info("Emulator seems stuck. Sending kill signal.")
|
||||||
self.process.kill()
|
self.process.kill()
|
||||||
|
_RUNNING_PIDS.remove(self.process)
|
||||||
|
|
||||||
_rm_f(self.profile_dir / "trezor.pid")
|
_rm_f(self.profile_dir / "trezor.pid")
|
||||||
_rm_f(self.profile_dir / "trezor.port")
|
_rm_f(self.profile_dir / "trezor.port")
|
||||||
|
Loading…
Reference in New Issue
Block a user