Skip to content

Commit 6958d24

Browse files
committed
Fix setup of python import
This change means we can't specify unbuffered output to python so we also change the app code to always flush on output. Fixes issue #15.
1 parent 86b1062 commit 6958d24

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

sleep_inhibitor/sleep-inhibitor.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Description=Sleep Inhibitor Service
33

44
[Service]
5-
ExecStart=/usr/bin/python3 -u /usr/bin/%p
5+
ExecStart=/usr/bin/%p
66

77
[Install]
88
WantedBy=default.target

sleep_inhibitor/sleep_inhibitor.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python3 -u
1+
#!/usr/bin/python3
2+
23
'Program to run plugins to inhibit system sleep/suspend.'
34
# Mark Blakeney, Jul 2020.
45

@@ -22,6 +23,9 @@
2223

2324
TIMEMULTS = {'s': 1, 'm': 60, 'h': 3600}
2425

26+
def log(msg):
27+
print(msg, flush=True)
28+
2529
def conv_to_secs(val):
2630
'Convert given time string to float seconds'
2731
# Default input time value (without qualifier) is minutes
@@ -91,7 +95,7 @@ def __init__(self, index, prog, progname, period, period_on,
9195
self.icmd = shlex.split(f'{inhibitor_prog}{what} --who="{progname}" '
9296
f'--why="{self.name}" {prog} -s {period_on} -i "{cmd}"')
9397

94-
print(f'{self.name} [{path}] configured @ {period_str}/{period_on_str}')
98+
log(f'{self.name} [{path}] configured @ {period_str}/{period_on_str}')
9599

96100
async def run(self):
97101
'Worker function which runs as a asyncio task for each plugin'
@@ -102,16 +106,16 @@ async def run(self):
102106
while return_code == SUSP_CODE:
103107
if self.is_inhibiting is not True:
104108
self.is_inhibiting = True
105-
print(f'{self.name} is inhibiting '
106-
f'suspend (return={return_code})')
109+
log(f'{self.name} is inhibiting '
110+
f'suspend (return={return_code})')
107111

108112
proc = await asyncio.create_subprocess_exec(*self.icmd)
109113
return_code = await proc.wait()
110114

111115
if self.is_inhibiting is not False:
112116
self.is_inhibiting = False
113-
print(f'{self.name} is not inhibiting '
114-
f'suspend (return={return_code})')
117+
log(f'{self.name} is not inhibiting '
118+
f'suspend (return={return_code})')
115119

116120
await asyncio.sleep(self.period)
117121

@@ -133,7 +137,7 @@ def init():
133137
base_dir = Path(__file__).resolve().parent
134138

135139
if args.package_dir:
136-
print(base_dir)
140+
log(base_dir)
137141
sys.exit()
138142

139143
# This instance may be a child invocation merely to run and check
@@ -165,7 +169,7 @@ def init():
165169
continue
166170

167171
vers = res.stdout.split('\n')[0].strip()
168-
print(f'{progname} using {iprog}, {vers}')
172+
log(f'{progname} using {iprog}, {vers}')
169173
inhibitor_prog = iprog
170174

171175
if not inhibitor_prog:

0 commit comments

Comments
 (0)