My Operating System is Manjora17.1.12
, the Python version is 3.7.0
, and the Supervisor's version is 3.3.4
.
I have a python script, it just shows a notification. The code is:
import os
os.system('notify-send hello')
The supervisor config is :
[program:test_notify]
directory=/home/zz
command=python -u test_notify.py
stdout_logfile = /home/zz/supervisord.d/log/test_notify.log
stderr_logfile = /home/zz/supervisord.d/log/test_notify.log
But when I execute the python script with the supervisor, it doesn't show the notification.
Proper environment variables need to be set (DISPLAY & DBUS_SESSION_BUS_ADDRESS). You can do it in many different ways, depending on your needs, like e.g.
a) per subprocess
b) in script globally
c) in supervisor config per program
The above examples have a couple of assumptions (you may want to change these settings accordingly):
To run script as root and show notification for regular user, use sudo as described on Arch wiki Desktop_notifications.