Ensure temp files and other resources are cleaned up even if kitty crashes or is SIGKILLed

This commit is contained in:
Kovid Goyal
2025-01-05 12:51:59 +05:30
parent 48d5c90bb8
commit 334adf9c1a
9 changed files with 93 additions and 32 deletions

View File

@@ -10,6 +10,7 @@ import subprocess
import tempfile
from kitty.constants import kitten_exe, kitty_exe
from kitty.shm import SharedMemory
from . import BaseTest
@@ -51,8 +52,16 @@ raise SystemExit(p.wait())
open(os.path.join(sdir, 'f'), 'w').close()
select.select(readers, [], [], 10)
self.ae(read(), str(i+2))
shm = SharedMemory(size=64)
shm.write(b'1' * 64)
shm.flush()
p.stdin.write(f'shm_unlink {shm.name}\n'.encode())
p.stdin.flush()
self.ae(read(), str(i+3))
self.assertTrue(os.listdir(self.tdir))
shm2 = SharedMemory(shm.name)
self.ae(shm2.read()[:64], b'1' * 64)
# Ensure child is ignoring signals
os.kill(atexit_pid, signal.SIGINT)
@@ -74,6 +83,7 @@ raise SystemExit(p.wait())
os.waitpid(atexit_pid, 0)
except ChildProcessError:
pass
self.assertRaises(FileNotFoundError, lambda: SharedMemory(shm.name))
r('close')
r('terminate')