Skip to content

Commit

Permalink
Merge pull request #813 from troycurtisjr/no-hang-on-exit
Browse files Browse the repository at this point in the history
Use GLib.spawn_async() for app launching to auto-reap children.
  • Loading branch information
friday committed Sep 13, 2021
2 parents 529f9b9 + 844d822 commit 6059d50
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions ulauncher/api/shared/action/LaunchAppAction.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import logging
import os
import subprocess
import re
import shlex
import shutil
from pathlib import Path
import gi

gi.require_version("GLib", "2.0")
# pylint: disable=wrong-import-position
from gi.repository import GLib

from ulauncher.utils.desktop.reader import read_desktop_file
from ulauncher.utils.decorator.run_async import run_async
from ulauncher.utils.Settings import Settings
from ulauncher.api.shared.action.BaseAction import BaseAction

Expand All @@ -16,11 +19,6 @@
hasSystemdRun = bool(shutil.which("systemd-run"))


@run_async
def wait_for_pid(pid):
os.waitpid(pid, 0)


class LaunchAppAction(BaseAction):
"""
Launches app by given `.desktop` file path
Expand Down Expand Up @@ -72,8 +70,13 @@ def run(self):

try:
logger.info('Run application %s (%s) Exec %s', app.get_name(), self.filename, exec)
# Start_new_session is only needed if systemd-run is missing
pid = subprocess.Popen(sanitized_exec, env=env, start_new_session=True).pid
wait_for_pid(pid)
envp = ["{}={}".format(k, v) for k, v in env.items()]
GLib.spawn_async(
argv=sanitized_exec,
envp=envp,
flags=GLib.SpawnFlags.SEARCH_PATH_FROM_ENVP | GLib.SpawnFlags.SEARCH_PATH,
# setsid is really only needed if systemd-run is missing, but doesn't hurt to have.
child_setup=os.setsid
)
except Exception as e:
logger.error('%s: %s', type(e).__name__, e)

0 comments on commit 6059d50

Please sign in to comment.