Skip to content

Commit

Permalink
chore: fix bridge stop command not working
Browse files Browse the repository at this point in the history
  • Loading branch information
vdovhanych committed Aug 25, 2024
1 parent 48bfc3c commit f63bae4
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import socket
import time
from shlex import split
from typing import TYPE_CHECKING

from psutil import Popen
Expand Down Expand Up @@ -97,14 +98,14 @@ def start(version: str, proxy: bool = False, output_to_logfile: bool = True) ->
if helpers.physical_trezor()
else f"{bridge_location} -ed 21324:21325 -u=false"
)

# Conditionally redirecting the output to a logfile instead of terminal/stdout
command_list = split(command)
if output_to_logfile:
log_file = open(helpers.EMU_BRIDGE_LOG, "a")
log(f"All the bridge debug output redirected to {helpers.EMU_BRIDGE_LOG}")
BRIDGE = Popen(command, shell=True, stdout=log_file, stderr=log_file)
BRIDGE = Popen(command_list, stdout=log_file, stderr=log_file)
else:
BRIDGE = Popen(command, shell=True)
BRIDGE = Popen(command_list)

log(f"Bridge spawned: {BRIDGE}. CMD: {BRIDGE.cmdline()}")

Expand All @@ -129,10 +130,22 @@ def stop(proxy: bool = True) -> None:
global VERSION_RUNNING

if BRIDGE is None:
log("WARNING: Attempting to stop a brige, but it is not running", "red")
log("WARNING: Attempting to stop a bridge, but it is not running", "red")
else:
BRIDGE.kill()
log(f"Bridge killed: {BRIDGE}")
try:
BRIDGE.terminate()
BRIDGE.wait(timeout=5)
except Exception as e:
log(f"Termination failed: {e}, killing process.", "yellow")
BRIDGE.kill()
BRIDGE.wait()

# Ensuring all child processes are cleaned up
for child in BRIDGE.children(recursive=True):
log(f"Killing child process {child.pid}")
child.kill()
child.wait()

BRIDGE = None
VERSION_RUNNING = None

Expand Down

0 comments on commit f63bae4

Please sign in to comment.