Skip to content

Commit

Permalink
Sesnd SIGINT to end port-forward
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenh committed Nov 26, 2024
1 parent 5054425 commit 752f0fc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tools/ktest/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,21 @@ def forward(self, svc: str, ports: Mapping[int, int]):
yield proc
finally:
logger.debug("terminating port-forward: %s", svc)
for stop in (proc.terminate, proc.kill):

def ctrl_c():
proc.send_signal(signal.SIGINT)

for stop in (ctrl_c, proc.terminate, proc.kill):
logger.debug("attempting to '%s' port-forward: %s", stop.__name__, svc)
stop()
try:
proc.communicate(timeout=3)
outs, errs = proc.communicate(timeout=3)
logger.debug("port-forward exited: %s", svc)
logger.debug("stdout: %s", outs)
logger.debug("stderr: %s", errs)

# wait for the port to become available again
time.sleep(3)
time.sleep(5)
break
except subprocess.TimeoutExpired:
logger.info("timeout expired waiting for: %s", svc)
Expand Down

0 comments on commit 752f0fc

Please sign in to comment.