mirror of
https://github.com/AdnanHodzic/auto-cpufreq.git
synced 2025-07-28 08:04:25 +02:00
GUI: switch to ThreadPool for daemon stuff
This commit is contained in:
parent
2bbcdcb8e4
commit
235d1a48de
@ -7,7 +7,7 @@ from gi.repository import Gtk, GdkPixbuf
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import platform as pl
|
import platform as pl
|
||||||
from threading import Thread
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
sys.path.append("../../")
|
sys.path.append("../../")
|
||||||
from subprocess import getoutput, run, PIPE
|
from subprocess import getoutput, run, PIPE
|
||||||
@ -187,7 +187,10 @@ class DropDownMenu(Gtk.MenuButton):
|
|||||||
if response == Gtk.ResponseType.YES:
|
if response == Gtk.ResponseType.YES:
|
||||||
try:
|
try:
|
||||||
# run in thread to prevent GUI from hanging
|
# run in thread to prevent GUI from hanging
|
||||||
result = Thread(target=run, args=("pkexec auto-cpufreq --remove",), kwargs={"shell": True, "stdout": PIPE, "stderr": PIPE}).start()
|
with ThreadPoolExecutor() as executor:
|
||||||
|
kwargs = {"shell": True, "stdout": PIPE, "stderr": PIPE}
|
||||||
|
future = executor.submit(run, "pkexec auto-cpufreq --remove", **kwargs)
|
||||||
|
result = future.result()
|
||||||
if result.stderr.decode() == PKEXEC_ERROR:
|
if result.stderr.decode() == PKEXEC_ERROR:
|
||||||
raise Exception("Authorization was cancelled")
|
raise Exception("Authorization was cancelled")
|
||||||
dialog = Gtk.MessageDialog(
|
dialog = Gtk.MessageDialog(
|
||||||
@ -270,7 +273,10 @@ class DaemonNotRunningView(Gtk.Box):
|
|||||||
def install_daemon(self, button, parent):
|
def install_daemon(self, button, parent):
|
||||||
try:
|
try:
|
||||||
# run in thread to prevent GUI from hanging
|
# run in thread to prevent GUI from hanging
|
||||||
result = Thread(target=run, args=("pkexec auto-cpufreq --install",), kwargs={"shell": True, "stdout": PIPE, "stderr": PIPE}).start()
|
with ThreadPoolExecutor() as executor:
|
||||||
|
kwargs = {"shell": True, "stdout": PIPE, "stderr": PIPE}
|
||||||
|
future = executor.submit(run, "pkexec auto-cpufreq --install", **kwargs)
|
||||||
|
result = future.result()
|
||||||
if result.stderr.decode() == PKEXEC_ERROR:
|
if result.stderr.decode() == PKEXEC_ERROR:
|
||||||
raise Exception("Authorization was cancelled")
|
raise Exception("Authorization was cancelled")
|
||||||
elif result.stderr is not None:
|
elif result.stderr is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user