From 7b08777d77d6cfd5a4eeeee81fb51f5fdedde987 Mon Sep 17 00:00:00 2001 From: mw Date: Wed, 19 Jun 2019 22:26:48 +0200 Subject: [PATCH 01/14] Add support for switching dpms --- bumblebee/modules/caffeine.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 2354ed0..91fb0e9 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -39,9 +39,11 @@ class Module(bumblebee.engine.Module): def _toggle(self, widget): if self._active(): + bumblebee.util.execute("xset +dpms") bumblebee.util.execute("xset s default") bumblebee.util.execute("notify-send \"Out of coffee\"") else: + bumblebee.util.execute("xset -dpms") bumblebee.util.execute("xset s off") bumblebee.util.execute("notify-send \"Consuming caffeine\"") From 61fe85842a0c932c4a8375f657eb06f406344ace Mon Sep 17 00:00:00 2001 From: mw Date: Sun, 25 Aug 2019 20:53:42 +0200 Subject: [PATCH 02/14] Use xdg-screensaver instead of xset --- bumblebee/modules/caffeine.py | 42 +++++++++++++++-------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 91fb0e9..3002dfb 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -1,9 +1,9 @@ -# pylint: disable=C0111,R0903 +#pylint: disable=C0111,R0903 """Enable/disable automatic screen locking. Requires the following executables: - * xset + * xdg-screensaver * notify-send """ @@ -14,37 +14,31 @@ import bumblebee.engine class Module(bumblebee.engine.Module): def __init__(self, engine, config): super(Module, self).__init__(engine, config, - bumblebee.output.Widget(full_text=self.caffeine) + bumblebee.output.Widget(full_text="") ) + self._active = False + self.interval(1) + engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self._toggle ) - def caffeine(self, widget): - return "" - def state(self, widget): - if self._active(): + if self._active: return "activated" return "deactivated" - def _active(self): - for line in bumblebee.util.execute("xset q").split("\n"): - if "timeout" in line: - timeout = int(line.split(" ")[4]) - if timeout == 0: - return True - return False - return False - - def _toggle(self, widget): - if self._active(): - bumblebee.util.execute("xset +dpms") - bumblebee.util.execute("xset s default") - bumblebee.util.execute("notify-send \"Out of coffee\"") - else: - bumblebee.util.execute("xset -dpms") - bumblebee.util.execute("xset s off") + def _toggle(self, event): + self._active = not self._active + if self._active: + bumblebee.util.execute("xdg-screensaver reset") bumblebee.util.execute("notify-send \"Consuming caffeine\"") + else: + bumblebee.util.execute("notify-send \"Out of coffee\"") + + def update(self, widgets): + if self._active: + bumblebee.util.execute("xdg-screensaver reset") + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From c05fc3ae4d6ac0ed459150acf2c19fd892c2ea9f Mon Sep 17 00:00:00 2001 From: mw Date: Sun, 25 Aug 2019 21:08:00 +0200 Subject: [PATCH 03/14] Add some basic error handling in case the executables don't exist --- bumblebee/modules/caffeine.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 3002dfb..0db8fad 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -30,11 +30,14 @@ class Module(bumblebee.engine.Module): def _toggle(self, event): self._active = not self._active - if self._active: - bumblebee.util.execute("xdg-screensaver reset") - bumblebee.util.execute("notify-send \"Consuming caffeine\"") - else: - bumblebee.util.execute("notify-send \"Out of coffee\"") + try: + if self._active: + bumblebee.util.execute("xdg-screensaver reset") + bumblebee.util.execute("notify-send \"Consuming caffeine\"") + else: + bumblebee.util.execute("notify-send \"Out of coffee\"") + except: + self._active = not self._active def update(self, widgets): if self._active: From 6652a581dfd2ec4700bd9ce54d9cd88647dc099f Mon Sep 17 00:00:00 2001 From: mw Date: Tue, 27 Aug 2019 21:31:50 +0200 Subject: [PATCH 04/14] PoC using xdg-screensaver's suspend mechanisms --- bumblebee/modules/caffeine.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 0db8fad..7b2e290 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -4,12 +4,15 @@ Requires the following executables: * xdg-screensaver + * xdotool * notify-send """ import bumblebee.input import bumblebee.output import bumblebee.engine +import psutil +import os class Module(bumblebee.engine.Module): def __init__(self, engine, config): @@ -17,7 +20,7 @@ class Module(bumblebee.engine.Module): bumblebee.output.Widget(full_text="") ) self._active = False - self.interval(1) + self._xid = 0 engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self._toggle @@ -32,16 +35,16 @@ class Module(bumblebee.engine.Module): self._active = not self._active try: if self._active: - bumblebee.util.execute("xdg-screensaver reset") + self._xid = bumblebee.util.execute("xdotool search --class \"i3bar\"").strip() + bumblebee.util.execute("xdg-screensaver suspend {}".format(self._xid)) bumblebee.util.execute("notify-send \"Consuming caffeine\"") else: + for process in psutil.process_iter(): + if process.cmdline() == ['/usr/bin/xprop','-id',str(self._xid),'-spy']: + pid = process.pid + os.kill(pid,9) bumblebee.util.execute("notify-send \"Out of coffee\"") except: self._active = not self._active - def update(self, widgets): - if self._active: - bumblebee.util.execute("xdg-screensaver reset") - - # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From b59ecc8aac71232186f234b8bf4669bbc18a64b0 Mon Sep 17 00:00:00 2001 From: mw Date: Wed, 28 Aug 2019 00:09:04 +0200 Subject: [PATCH 05/14] PoC use double fork to escape SIGSTOP --- bumblebee/modules/caffeine.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 7b2e290..fa2876e 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -36,7 +36,13 @@ class Module(bumblebee.engine.Module): try: if self._active: self._xid = bumblebee.util.execute("xdotool search --class \"i3bar\"").strip() - bumblebee.util.execute("xdg-screensaver suspend {}".format(self._xid)) + pid = os.fork() + if pid == 0: + os.setsid() + bumblebee.util.execute("xdg-screensaver suspend {}".format(self._xid)) + os._exit(0) + else: + os.waitpid(pid,0) bumblebee.util.execute("notify-send \"Consuming caffeine\"") else: for process in psutil.process_iter(): From 2c861a3092ee88782be04ab1cb60f32da1a57292 Mon Sep 17 00:00:00 2001 From: mw Date: Sun, 1 Sep 2019 22:38:22 +0200 Subject: [PATCH 06/14] Clean up --- bumblebee/modules/caffeine.py | 81 +++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index fa2876e..75bea15 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -5,14 +5,16 @@ Requires the following executables: * xdg-screensaver * xdotool + * xprop (as dependency for xdotool) * notify-send """ +import psutil +import os +import logging import bumblebee.input import bumblebee.output import bumblebee.engine -import psutil -import os class Module(bumblebee.engine.Module): def __init__(self, engine, config): @@ -20,37 +22,72 @@ class Module(bumblebee.engine.Module): bumblebee.output.Widget(full_text="") ) self._active = False - self._xid = 0 + self._xid = None engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self._toggle ) + def _check_requirements(self): + requirements = ['xdotool','xprop','xdg-screensaver'] + missing = [] + for tool in requirements: + if not bumblebee.util.which(tool): + missing.append(tool) + return missing + + def _get_i3bar_xid(self): + xid = bumblebee.util.execute("xdotool search --class \"i3bar\"").partition('\n')[0].strip() + if xid.isdigit(): + return xid + else: + logging.info("Module caffeine: xdotool couldn't get X window ID of \"i3bar\".") + return None + + def _notify(self): + if not bumblebee.util.which('notify-send'): + return + + if self._active: + bumblebee.util.execute("notify-send \"Consuming caffeine\"") + else: + bumblebee.util.execute("notify-send \"Out of coffee\"") + + def _suspend_screensaver(self): + self._xid = self._get_i3bar_xid() + if self._xid == None: + return + + pid = os.fork() + if pid == 0: + os.setsid() + bumblebee.util.execute("xdg-screensaver suspend {}".format(self._xid)) + os._exit(0) + else: + os.waitpid(pid,0) + + def _resume_screensaver(self): + for process in psutil.process_iter(): + if process.cmdline() == [bumblebee.util.which('xprop'),'-id',str(self._xid),'-spy']: + pid = process.pid + os.kill(pid,9) + def state(self, widget): if self._active: return "activated" return "deactivated" def _toggle(self, event): + missing = self._check_requirements() + if missing: + logging.warning("Could not run caffeine - missing {}!".format(", ".join(missing))) + return + self._active = not self._active - try: - if self._active: - self._xid = bumblebee.util.execute("xdotool search --class \"i3bar\"").strip() - pid = os.fork() - if pid == 0: - os.setsid() - bumblebee.util.execute("xdg-screensaver suspend {}".format(self._xid)) - os._exit(0) - else: - os.waitpid(pid,0) - bumblebee.util.execute("notify-send \"Consuming caffeine\"") - else: - for process in psutil.process_iter(): - if process.cmdline() == ['/usr/bin/xprop','-id',str(self._xid),'-spy']: - pid = process.pid - os.kill(pid,9) - bumblebee.util.execute("notify-send \"Out of coffee\"") - except: - self._active = not self._active + if self._active: + self._suspend_screensaver() + else: + self._resume_screensaver() + self._notify() # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 4743558a689d9e168f6402aa316bd9b1979f352e Mon Sep 17 00:00:00 2001 From: mw Date: Sun, 1 Sep 2019 22:54:38 +0200 Subject: [PATCH 07/14] Add fixes --- bumblebee/modules/caffeine.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 75bea15..84a4f3b 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -9,9 +9,9 @@ Requires the following executables: * notify-send """ -import psutil -import os import logging +import os +import psutil import bumblebee.input import bumblebee.output import bumblebee.engine @@ -40,8 +40,7 @@ class Module(bumblebee.engine.Module): xid = bumblebee.util.execute("xdotool search --class \"i3bar\"").partition('\n')[0].strip() if xid.isdigit(): return xid - else: - logging.info("Module caffeine: xdotool couldn't get X window ID of \"i3bar\".") + logging.info("Module caffeine: xdotool couldn't get X window ID of \"i3bar\".") return None def _notify(self): @@ -55,7 +54,7 @@ class Module(bumblebee.engine.Module): def _suspend_screensaver(self): self._xid = self._get_i3bar_xid() - if self._xid == None: + if self._xid is None: return pid = os.fork() From 0b9829bc77f8e535ac0895a17e35cfac45c9b0d0 Mon Sep 17 00:00:00 2001 From: mw Date: Mon, 2 Sep 2019 16:42:25 +0200 Subject: [PATCH 08/14] Make pylint happy --- bumblebee/modules/caffeine.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 84a4f3b..935cfb2 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -23,13 +23,13 @@ class Module(bumblebee.engine.Module): ) self._active = False self._xid = None - + engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self._toggle ) def _check_requirements(self): - requirements = ['xdotool','xprop','xdg-screensaver'] + requirements = ['xdotool', 'xprop', 'xdg-screensaver'] missing = [] for tool in requirements: if not bumblebee.util.which(tool): @@ -56,27 +56,27 @@ class Module(bumblebee.engine.Module): self._xid = self._get_i3bar_xid() if self._xid is None: return - + pid = os.fork() if pid == 0: os.setsid() bumblebee.util.execute("xdg-screensaver suspend {}".format(self._xid)) os._exit(0) else: - os.waitpid(pid,0) - + os.waitpid(pid, 0) + def _resume_screensaver(self): for process in psutil.process_iter(): - if process.cmdline() == [bumblebee.util.which('xprop'),'-id',str(self._xid),'-spy']: + if process.cmdline() == [bumblebee.util.which('xprop'), '-id', str(self._xid), '-spy']: pid = process.pid - os.kill(pid,9) + os.kill(pid, 9) - def state(self, widget): + def state(self, _): if self._active: return "activated" return "deactivated" - def _toggle(self, event): + def _toggle(self, _): missing = self._check_requirements() if missing: logging.warning("Could not run caffeine - missing {}!".format(", ".join(missing))) From 43b29eedd240c7aebfefc535381c8256b8f87340 Mon Sep 17 00:00:00 2001 From: mw Date: Mon, 2 Sep 2019 16:53:10 +0200 Subject: [PATCH 09/14] Fix pylint logging warning, exclude W0212 --- bumblebee/modules/caffeine.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 935cfb2..b0e7d57 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -1,4 +1,4 @@ -#pylint: disable=C0111,R0903 +#pylint: disable=C0111,R0903,W0212 """Enable/disable automatic screen locking. @@ -40,7 +40,7 @@ class Module(bumblebee.engine.Module): xid = bumblebee.util.execute("xdotool search --class \"i3bar\"").partition('\n')[0].strip() if xid.isdigit(): return xid - logging.info("Module caffeine: xdotool couldn't get X window ID of \"i3bar\".") + logging.warning("Module caffeine: xdotool couldn't get X window ID of \"i3bar\".") return None def _notify(self): @@ -79,7 +79,7 @@ class Module(bumblebee.engine.Module): def _toggle(self, _): missing = self._check_requirements() if missing: - logging.warning("Could not run caffeine - missing {}!".format(", ".join(missing))) + logging.warning('Could not run caffeine - missing %s!', ", ".join(missing)) return self._active = not self._active From 43988db4cc07a850b5f0d4aebfbde6ab9308e706 Mon Sep 17 00:00:00 2001 From: mw Date: Mon, 2 Sep 2019 17:26:01 +0200 Subject: [PATCH 10/14] Make sure state is reverted in case of error --- bumblebee/modules/caffeine.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index b0e7d57..86de530 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -55,7 +55,7 @@ class Module(bumblebee.engine.Module): def _suspend_screensaver(self): self._xid = self._get_i3bar_xid() if self._xid is None: - return + return False pid = os.fork() if pid == 0: @@ -64,12 +64,16 @@ class Module(bumblebee.engine.Module): os._exit(0) else: os.waitpid(pid, 0) + return True def _resume_screensaver(self): for process in psutil.process_iter(): if process.cmdline() == [bumblebee.util.which('xprop'), '-id', str(self._xid), '-spy']: - pid = process.pid - os.kill(pid, 9) + try: + os.kill(process.pid, 9) + except OSError: + return False + return True def state(self, _): if self._active: @@ -84,9 +88,13 @@ class Module(bumblebee.engine.Module): self._active = not self._active if self._active: - self._suspend_screensaver() + success = self._suspend_screensaver() else: - self._resume_screensaver() - self._notify() + success = self._resume_screensaver() + + if success: + self._notify() + else: + self._active = not self._active # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From ac418caa59b9299cd7003fa37cf240700de61265 Mon Sep 17 00:00:00 2001 From: mw Date: Thu, 5 Sep 2019 20:19:20 +0200 Subject: [PATCH 11/14] Add test cases --- tests/modules/test_caffeine.py | 63 ++++++++++++++++------------------ 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/tests/modules/test_caffeine.py b/tests/modules/test_caffeine.py index e95e2ac..ad0cf00 100644 --- a/tests/modules/test_caffeine.py +++ b/tests/modules/test_caffeine.py @@ -1,17 +1,9 @@ # pylint: disable=C0103,C0111 -import json import unittest -import mock - -try: - from StringIO import StringIO -except ImportError: - from io import StringIO - +from mock import patch import tests.mocks as mocks -from bumblebee.config import Config from bumblebee.input import LEFT_MOUSE from bumblebee.modules.caffeine import Module @@ -19,35 +11,40 @@ class TestCaffeineModule(unittest.TestCase): def setUp(self): mocks.setup_test(self, Module) - self.xset_active = " timeout: 0 cycle: 123" - self.xset_inactive = " timeout: 600 cycle: 123" - def tearDown(self): mocks.teardown_test(self) - def test_text(self): - self.assertEquals(self.module.caffeine(self.anyWidget), "") + def test_check_requirements(self): + with patch('bumblebee.util.which', side_effect=['', 'xprop', 'xdg-screensaver']): + self.assertTrue(['xdotool'] == self.module._check_requirements()) - def test_active(self): - self.popen.mock.communicate.return_value = (self.xset_active, None) - self.assertTrue(not "deactivated" in self.module.state(self.anyWidget)) - self.assertTrue("activated" in self.module.state(self.anyWidget)) + def test_get_i3bar_xid_returns_digit(self): + self.popen.mock.communicate.return_value = ("8388614", None) + self.assertTrue(self.module._get_i3bar_xid().isdigit()) - def test_inactive(self): - self.popen.mock.communicate.return_value = (self.xset_inactive, None) - self.assertTrue("deactivated" in self.module.state(self.anyWidget)) - self.popen.mock.communicate.return_value = ("no text", None) - self.assertTrue("deactivated" in self.module.state(self.anyWidget)) + def test_get_i3bar_xid_returns_error_string(self): + self.popen.mock.communicate.return_value = ("Some error message", None) + self.assertTrue(self.module._get_i3bar_xid() is None) - def test_toggle(self): - self.popen.mock.communicate.return_value = (self.xset_active, None) - mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module) - self.popen.assert_call("xset s default") - self.popen.assert_call("notify-send \"Out of coffee\"") - - self.popen.mock.communicate.return_value = (self.xset_inactive, None) - mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module) - self.popen.assert_call("xset s off") - self.popen.assert_call("notify-send \"Consuming caffeine\"") + def test_get_i3bar_xid_returns_empty_string(self): + self.popen.mock.communicate.return_value = ("", None) + self.assertTrue(self.module._get_i3bar_xid() is None) + + def test_suspend_screensaver_success(self): + with patch.object(self.module, '_get_i3bar_xid', return_value=8388614): + mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module) + self.assertTrue(self.module._suspend_screensaver() is True) + + def test_suspend_screensaver_fail(self): + with patch.object(self.module, '_get_i3bar_xid', return_value=None): + self.module._active = False + mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module) + self.assertTrue(self.module._suspend_screensaver() is False) + + def test_resume_screensaver(self): + with patch.object(self.module, '_check_requirements', return_value=[]): + self.module._active = True + mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module) + self.assertTrue(self.module._resume_screensaver() is True) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From a5ef86364706038e1bb2178820eaa915abcfd581 Mon Sep 17 00:00:00 2001 From: mw Date: Thu, 5 Sep 2019 20:48:19 +0200 Subject: [PATCH 12/14] Rewrite killing of xprop --- bumblebee/modules/caffeine.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 86de530..a90a7d7 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -67,13 +67,17 @@ class Module(bumblebee.engine.Module): return True def _resume_screensaver(self): + pids = [] + success = True for process in psutil.process_iter(): if process.cmdline() == [bumblebee.util.which('xprop'), '-id', str(self._xid), '-spy']: - try: - os.kill(process.pid, 9) - except OSError: - return False - return True + pids.append(process.pid) + for pid in pids: + try: + os.kill(process.pid, 9) + except OSError: + success = False + return success def state(self, _): if self._active: From f19cf652cb7b9363fb74eada932aa0a059f98d08 Mon Sep 17 00:00:00 2001 From: mw Date: Thu, 5 Sep 2019 21:08:05 +0200 Subject: [PATCH 13/14] Try to make codeclimate happy --- bumblebee/modules/caffeine.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index a90a7d7..1f39a9e 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -69,8 +69,9 @@ class Module(bumblebee.engine.Module): def _resume_screensaver(self): pids = [] success = True + xprop_path = bumblebee.util.which('xprop') for process in psutil.process_iter(): - if process.cmdline() == [bumblebee.util.which('xprop'), '-id', str(self._xid), '-spy']: + if process.cmdline() == [xprop_path, '-id', str(self._xid), '-spy']: pids.append(process.pid) for pid in pids: try: From ed59823ac3fbfe8c8710b858219599b93c8e8a9a Mon Sep 17 00:00:00 2001 From: mw Date: Thu, 5 Sep 2019 21:57:32 +0200 Subject: [PATCH 14/14] Fix _resume_screensaver --- bumblebee/modules/caffeine.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bumblebee/modules/caffeine.py b/bumblebee/modules/caffeine.py index 1f39a9e..ed9633c 100644 --- a/bumblebee/modules/caffeine.py +++ b/bumblebee/modules/caffeine.py @@ -67,15 +67,12 @@ class Module(bumblebee.engine.Module): return True def _resume_screensaver(self): - pids = [] success = True xprop_path = bumblebee.util.which('xprop') - for process in psutil.process_iter(): - if process.cmdline() == [xprop_path, '-id', str(self._xid), '-spy']: - pids.append(process.pid) + pids = [ p.pid for p in psutil.process_iter() if p.cmdline() == [xprop_path, '-id', str(self._xid), '-spy'] ] for pid in pids: try: - os.kill(process.pid, 9) + os.kill(pid, 9) except OSError: success = False return success