Skip to content

Commit

Permalink
qubes-rpc/nautilus: Execute external commands asynchronously
Browse files Browse the repository at this point in the history
Using GLib.spawn_async instead of subprocess.call or subprocess.Popen
This prevents Nautilus from getting stuck while executing external commands. And no zombies.
  • Loading branch information
noskb committed Nov 30, 2022
1 parent 0f7f0d6 commit 119eb3a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
7 changes: 3 additions & 4 deletions qubes-rpc/nautilus/qvm_copy_nautilus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import subprocess

from gi.repository import Nautilus, GObject
from gi.repository import Nautilus, GObject, GLib


class CopyToAppvmItemExtension(GObject.GObject, Nautilus.MenuProvider):
Expand Down Expand Up @@ -35,4 +33,5 @@ def on_menu_item_clicked(self, menu, files):
# Check if file is not gone
if not file_obj.is_gone()]
cmd.insert(0, '/usr/lib/qubes/qvm-copy-to-vm.gnome')
subprocess.call(cmd)
pid = GLib.spawn_async(cmd)[0]
GLib.spawn_close_pid(pid)
14 changes: 4 additions & 10 deletions qubes-rpc/nautilus/qvm_dvm_nautilus.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import os
from subprocess import Popen

from gi.repository import Nautilus, GObject
from gi.repository import Nautilus, GObject, GLib


class OpenInDvmItemExtension(GObject.GObject, Nautilus.MenuProvider):
Expand Down Expand Up @@ -49,13 +46,10 @@ def on_menu_item_clicked(self, menu, files, view_only=False):

gio_file = file_obj.get_location()

# Use subprocess.DEVNULL in python >= 3.3
devnull = open(os.devnull, 'wb')
command = ['nohup', '/usr/bin/qvm-open-in-dvm']
command = ['/usr/bin/qvm-open-in-dvm']
if view_only:
command.append('--view-only')
command.append(gio_file.get_path())

# Use Popen instead of subprocess.call to spawn the process
Popen(command, stdout=devnull, stderr=devnull)
devnull.close()
pid = GLib.spawn_async(command)[0]
GLib.spawn_close_pid(pid)
7 changes: 3 additions & 4 deletions qubes-rpc/nautilus/qvm_move_nautilus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import subprocess

from gi.repository import Nautilus, GObject
from gi.repository import Nautilus, GObject, GLib


class MoveToAppvmItemExtension(GObject.GObject, Nautilus.MenuProvider):
Expand Down Expand Up @@ -35,4 +33,5 @@ def on_menu_item_clicked(self, menu, files):
# Check if file is not gone
if not file_obj.is_gone()]
cmd.insert(0, '/usr/lib/qubes/qvm-move-to-vm.gnome')
subprocess.call(cmd)
pid = GLib.spawn_async(cmd)[0]
GLib.spawn_close_pid(pid)

0 comments on commit 119eb3a

Please sign in to comment.