Multithread app, runned as a service is not printing out things

18 Views Asked by At

I have this multithread app in python. I start 3 threads in main.py, and one of these threads just launch feh with this function:

def run_feh(delay=10):
    commands = f'''export DISPLAY=:0.0 && feh --hide-pointer --fullscreen --slideshow-delay {str(delay)} &'''
    process = subprocess.Popen(commands, shell=True, cwd="folder with pics", stdout=subprocess.DEVNULL)
    return process.pid

The problem is that, when I run the app from a terminal, with .venv active and python main.py, everything works fine, and all of the print messages are working correctly.

But when I run the app as a service with systemd, I just lose control of stdout when feh starts. I've been trying several solution (i.e. different methods from subprocess lib), but nothing seems to work.

[Unit]
Description=blabla
After=graphical.target

[Service]
User=<myuser>
WorkingDirectory=<Path to project folder>
ExecStartPre=<some script for gpio>
ExecStart=<venv bin python> <main.py inside project folder>

[Install]
WantedBy=multi-user.target

I'm seeing logs with 'sudo journalctl -u -f'

I know maybe it's not the best solution, but at this point i just want to know why it behaves so differently as a service.

I tried to see logs with sudo journalctl -u <service name> -f expecting same output as python main.py but all of the prints were lost after feh service was launched.

0

There are 0 best solutions below