msqlr = subprocess.Popen('sudo /bin/netstat -al'.split(), stdout=subprocess
    .PIPE).stdout
grep = subprocess.Popen(['/bin/grep', 'mysql'], stdin=msqlr, stdout=
    subprocess.PIPE).stdout
msqlrLines = grep.read().split('\n')
vals = map(string.strip, msqlrLines[0].split())
print(vals)
if len(vals) and vals[-1] in ('LISTENING', 'LISTEN'):
    print('OK - MySQL is running.')
else:
    print('Not OK - MySQL is not running.')
how to find out with python on ubuntu if MySQL is running?