mirror of
https://github.com/lutris/lutris
synced 2024-09-05 23:46:21 +00:00
Fix process watcher
This commit is contained in:
parent
838b46d0e1
commit
2f170e961f
|
@ -117,7 +117,8 @@ def main():
|
|||
signal.signal(signal.SIGTERM, hard_sig_handler)
|
||||
signal.signal(signal.SIGINT, hard_sig_handler)
|
||||
for child in watcher.iterate_children():
|
||||
kill_pid(child.pid)
|
||||
kill_pid(child.pid, signum == signal.SIGKILL)
|
||||
log("--terminated processes--")
|
||||
|
||||
signal.signal(signal.SIGTERM, sig_handler)
|
||||
signal.signal(signal.SIGINT, sig_handler)
|
||||
|
@ -159,21 +160,36 @@ def main():
|
|||
|
||||
log("Start monitoring process.")
|
||||
try:
|
||||
# The initial wait loop:
|
||||
# the initial process may have been excluded. Wait for the game
|
||||
# to be considered "started".
|
||||
if not watcher.is_alive():
|
||||
log("Waiting for game to start (first non-excluded process started)")
|
||||
while not watcher.is_alive():
|
||||
reap_children()
|
||||
time.sleep(0.1)
|
||||
|
||||
while watcher.is_alive():
|
||||
reap_children()
|
||||
time.sleep(0.1)
|
||||
|
||||
log("Monitored process exited.")
|
||||
reap_children()
|
||||
|
||||
# The game is no longer running. We kill other processes
|
||||
for child in watcher.iterate_children():
|
||||
kill_pid(child.pid)
|
||||
kill_pid(child.pid, True)
|
||||
|
||||
reap_children()
|
||||
log("All monitored processes have exited.")
|
||||
|
||||
except NoMoreChildren:
|
||||
log("All processes have quit")
|
||||
|
||||
if returncode is None:
|
||||
log("Failed to read return code from process")
|
||||
returncode = -1
|
||||
else:
|
||||
log("Process exited with returncode %s" % returncode)
|
||||
returncode = 0
|
||||
log("Monitored process didn't return an exit code.")
|
||||
log("Exit with returncode %s" % returncode)
|
||||
sys.exit(returncode)
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,13 @@ class LutrisWrapperTestCase(unittest.TestCase):
|
|||
try:
|
||||
# Wait for the "Hello World" message that indicates that the process
|
||||
# tree has started. This message arrives on stdout.
|
||||
for line in wrapper_proc.stdout:
|
||||
if line.strip() == b'Hello World':
|
||||
# We found the output we're looking for.
|
||||
break
|
||||
else:
|
||||
self.fail("stdout EOF unexpectedly")
|
||||
|
||||
# Wait a short while to see if lutris-wrapper will exit (it shouldn't)
|
||||
try:
|
||||
wrapper_proc.wait(0.5)
|
||||
|
@ -47,14 +54,8 @@ class LutrisWrapperTestCase(unittest.TestCase):
|
|||
self.fail("Process exited unexpectedly")
|
||||
finally:
|
||||
if wrapper_proc.returncode is None:
|
||||
wrapper_proc.kill()
|
||||
wrapper_proc.wait(3)
|
||||
for line in wrapper_proc.stdout:
|
||||
if line.strip() == b'Hello World':
|
||||
# We found the output we're looking for.
|
||||
break
|
||||
else:
|
||||
self.fail("stdout EOF unexpectedly")
|
||||
wrapper_proc.terminate()
|
||||
wrapper_proc.wait(30)
|
||||
wrapper_proc.stdout.close()
|
||||
|
||||
def test_cleanup_children(self):
|
||||
|
|
Loading…
Reference in a new issue