-
Notifications
You must be signed in to change notification settings - Fork 38
Description
In my project I needed a way to handle systemctl signals gracefully so I decided to use psystemd. Other alternatives did not perform properly. My main goal is to convert my Python script to executable and make it run as a service in the backgorund. The main problem I am facing rn is that my code cannot process systemctl stop signal gracefully. The way I implemented psystemd is given below.
from pystemd.systemd1 import Unit
if __name__ == "__main__":
try:
myc = Dlp_Service()
myc.start()
while True:
sleep(1)
if myc.unit.Unit.ActiveState == b"deactivating":
myc.stop()
except Exception as e:
print(e)
myc.stop()
It is initiated inside the Dlp_Service constructor like self.unit = Unit(b"myservice.service")
.
The error message is "ModuleNotFoundError: No module named 'pystemd.dbusexc'". The executable is created inside a virtual environment that has psystemd installed and this program works flawless as a Python script. How can i handle this error and use my program as executable?