(child, teleport_state, address)
| 47 | ui.say(f"starting Teleport proxy for '{app_name}'...") |
| 48 | |
| 49 | def wait(child, teleport_state, address): |
| 50 | wait_start = time.time() |
| 51 | |
| 52 | while time.time() - wait_start < 2: |
| 53 | child_terminated = child.poll() |
| 54 | if child_terminated: |
| 55 | other_tshs = [ |
| 56 | p.pid |
| 57 | for p in psutil.process_iter(["pid", "name"]) |
| 58 | if p.name() == "tsh" |
| 59 | ] |
| 60 | ui.warn(dedent(f""" |
| 61 | Teleport proxy failed to start, 'tsh' process already running! |
| 62 | existing 'tsh' processes: {other_tshs} |
| 63 | exit code: {child_terminated} |
| 64 | """)) |
| 65 | break |
| 66 | |
| 67 | # Timed out! Check if the process is running. |
| 68 | child_pid_status = psutil.pid_exists(child.pid) |
| 69 | if child_pid_status: |
| 70 | # Record the PID, if the process started successfully. |
| 71 | teleport_state.set_pid(app_name, child.pid) |
| 72 | teleport_state.set_address(app_name, address) |
| 73 | teleport_state.write() |
| 74 | |
| 75 | # Spawn a thread that will wait for the Teleport proxy to start, and |
| 76 | # record it's PID, or warn that it failed to start. |
no test coverage detected