Skip to content

Commit

Permalink
fix systemd availability check
Browse files Browse the repository at this point in the history
when the command is running, resource properties are always available.
  • Loading branch information
lilydjwg committed Jun 30, 2024
1 parent 8c70b42 commit e8b23af
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lilac2/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,22 @@ def _check_availability() -> bool | dict[str, bool]:
return False

try:
ps: dict[str, Optional[int]] = {
'CPUUsageNSec': None,
'MemoryPeak': None,
}
_read_service_int_properties('lilac-check', ps)

ret = {}
for k, v in ps.items():
ret[k] = v is not None

return ret
while True:
ps: dict[str, Optional[int]] = {
'CPUUsageNSec': None,
'MemoryPeak': None,
'MainPID': None,
}
_read_service_int_properties('lilac-check', ps)
if ps['MainPID'] != 0:
time.sleep(0.01)
continue

ret = {}
for k, v in ps.items():
ret[k] = v is not None

return ret
finally:
subprocess.run(['systemctl', '--user', 'stop', '--quiet', 'lilac-check'])

Expand Down

0 comments on commit e8b23af

Please sign in to comment.