Python subprocess output is logged by systemd twice

20 views Asked by At

In my application, I have the following code:

def ifdown(iface):
    rc = subprocess.run(['/sbin/ifdown', iface]).returncode
    if rc:
        print(f'ifdown({iface}) returned {rc}')
        return False
    return True

This application is run as a systemd service, the issue is when I call this function, the subprocess output is doubled in journalctl -e -u <my_service>:

May 10 13:42:25 evolve-4 dhclient[6319]: Killed old client process
May 10 13:42:25 evolve-4 python[1134]: Killed old client process
May 10 13:42:26 evolve-4 dhclient[6319]: Internet Systems Consortium DHCP Client 4.4.1
May 10 13:42:26 evolve-4 python[1134]: Internet Systems Consortium DHCP Client 4.4.1
May 10 13:42:26 evolve-4 python[1134]: Copyright 2004-2018 Internet Systems Consortium.
May 10 13:42:26 evolve-4 python[1134]: All rights reserved.
May 10 13:42:26 evolve-4 python[1134]: For info, please visit https://www.isc.org/software/dhcp/
May 10 13:42:26 evolve-4 dhclient[6319]: Copyright 2004-2018 Internet Systems Consortium.
May 10 13:42:26 evolve-4 python[1134]: Listening on LPF/wwan0/ee:bc:6c:be:6d:7c
May 10 13:42:26 evolve-4 python[1134]: Sending on   LPF/wwan0/ee:bc:6c:be:6d:7c
May 10 13:42:26 evolve-4 python[1134]: Sending on   Socket/fallback
May 10 13:42:26 evolve-4 dhclient[6319]: All rights reserved.
May 10 13:42:26 evolve-4 dhclient[6319]: For info, please visit https://www.isc.org/software/dhcp/
May 10 13:42:26 evolve-4 dhclient[6319]: 
May 10 13:42:26 evolve-4 python[1134]: DHCPRELEASE of 100.68.214.247 on wwan0 to 100.68.214.248 port 67
May 10 13:42:26 evolve-4 dhclient[6319]: Listening on LPF/wwan0/ee:bc:6c:be:6d:7c
May 10 13:42:26 evolve-4 dhclient[6319]: Sending on   LPF/wwan0/ee:bc:6c:be:6d:7c
May 10 13:42:26 evolve-4 dhclient[6319]: Sending on   Socket/fallback
May 10 13:42:26 evolve-4 dhclient[6319]: DHCPRELEASE of 100.68.214.247 on wwan0 to 100.68.214.248 port 67

I would like the output to be visible in real time, but only once. I don't care whether it will be attributed to parent or child process. How can I do it?

0

There are 0 answers