I'm trying to check on the status of the pigpiod process from within a python script. These two methods both appear to work so far. Are there any significant advantages or disadvantages of one over the other? Are these likely to be reliable ways to do this?
import os, commands def test_1(): try: n = int(os.popen('pidof pigpiod').read().splitlines()) except: n = None return n def test_2(): try: n = int(commands.getstatusoutput('pidof pigpiod')) except: n = None return n print "test 1: ", test_1() print "test 2: ", test_2()
pigpiod is running:
test 1: 2038 test 2: 2038
pigpiod has been stopped:
test 1: None test 2: None