1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-26 03:22:00 +03:00

test: wait a bit for the given PID to die if it's still alive

When playing around with the coverage-enabled build I kept hitting
an issue where dnsmasq failed to start because the previous instance was
still shutting down. This should, hopefully, help to mitigate that.
This commit is contained in:
Frantisek Sumsal 2021-10-21 15:59:57 +02:00
parent 97c373c7de
commit dded88acb9

View File

@ -3,6 +3,7 @@
# systemd-networkd tests
import argparse
import errno
import itertools
import os
import re
@ -483,6 +484,15 @@ def stop_by_pid_file(pid_file):
with open(pid_file, 'r') as f:
pid = f.read().rstrip(' \t\r\n\0')
os.kill(int(pid), signal.SIGTERM)
for _ in range(25):
try:
os.kill(int(pid), 0)
print(f"PID {pid} is still alive, waiting...")
time.sleep(.2)
except OSError as e:
if e.errno == errno.ESRCH:
break
print(f"Unexpected exception when waiting for {pid} to die: {e.errno}")
os.remove(pid_file)