Skip to content

Commit 7efc5da

Browse files
committed
Check for sleep ability at startup, not each run
1 parent c61fb94 commit 7efc5da

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setup(
1313
name=name,
14-
version='1.19',
14+
version='1.20',
1515
description='Program to run plugins to inhibit system '
1616
'sleep/suspend/hibernate',
1717
long_description=here.joinpath('README.md').read_text(),

sleep_inhibitor.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def run(self):
101101
await proc.wait()
102102

103103
while proc.returncode == SUSP_CODE:
104-
if not self.is_inhibiting:
104+
if self.is_inhibiting is not True:
105105
self.is_inhibiting = True
106106
print(f'{self.name} is inhibiting '
107107
f'suspend (return={proc.returncode})')
@@ -128,10 +128,6 @@ def init():
128128
opt.add_argument('-i', '--inhibit', help=argparse.SUPPRESS)
129129
args = opt.parse_args()
130130

131-
# Don't run if this system does not support sleep
132-
if not Path('/sys/power/state').read_text():
133-
sys.exit('System does not support any sleep states, quitting.')
134-
135131
# This instance may be a child invocation merely to run and check
136132
# the plugin while it is inhibiting.
137133
if args.inhibit:
@@ -142,6 +138,11 @@ def init():
142138
if res.returncode != SUSP_CODE:
143139
sys.exit(res.returncode)
144140

141+
# Don't run if this system does not support sleep
142+
pstate = Path('/sys/power/state')
143+
if not pstate.exists() or not pstate.read_text().strip():
144+
sys.exit('System does not support any sleep states, quitting.')
145+
145146
prog = Path(sys.argv[0]).resolve()
146147
progname = prog.stem.replace('_', '-')
147148

0 commit comments

Comments
 (0)