mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 18:22:09 +02:00
Reap zombies in a signal handler
Avoids relying on jernel behavior, which may not be portable across all unices
This commit is contained in:
@@ -244,6 +244,14 @@ def setup_profiling(args):
|
|||||||
print('To view the graphical call data, use: kcachegrind', cg)
|
print('To view the graphical call data, use: kcachegrind', cg)
|
||||||
|
|
||||||
|
|
||||||
|
def reap_zombies(*a):
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
os.waitpid(-1, os.WNOHANG)
|
||||||
|
except OSError:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
sys.setswitchinterval(1000.0) # we have only a single python thread
|
sys.setswitchinterval(1000.0) # we have only a single python thread
|
||||||
@@ -287,8 +295,8 @@ def main():
|
|||||||
raise SystemExit('GLFW initialization failed')
|
raise SystemExit('GLFW initialization failed')
|
||||||
try:
|
try:
|
||||||
with setup_profiling(args):
|
with setup_profiling(args):
|
||||||
# Let the kernel take care of reaping zombie child processes
|
# Avoid needing to launch threads to reap zombies
|
||||||
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
|
signal.signal(signal.SIGCHLD, reap_zombies)
|
||||||
run_app(opts, args)
|
run_app(opts, args)
|
||||||
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
|
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ def get_primary_selection():
|
|||||||
return '' # There is no primary selection on OS X
|
return '' # There is no primary selection on OS X
|
||||||
g = selection_clipboard_funcs()[0]
|
g = selection_clipboard_funcs()[0]
|
||||||
if g is None:
|
if g is None:
|
||||||
# We cannot use check_output as we set SIGCHLD to SIG_IGN
|
# We cannot use check_output as we set a SIGCHLD handler to reap zombies
|
||||||
ans = subprocess.Popen(['xsel', '-p'], stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
|
ans = subprocess.Popen(['xsel', '-p'], stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
|
||||||
if ans:
|
if ans:
|
||||||
# Without this for some reason repeated pastes dont work
|
# Without this for some reason repeated pastes dont work
|
||||||
|
|||||||
Reference in New Issue
Block a user