Super hacky but it works. See also: p.cmdline or p.exe if you have a different type of process you’re looking for (i.e. my script uses several params so I’m actually parsing p.cmdline because p.name is merely ‘python’)
import psutil
for p in psutil.process_iter():
if 'foo' in p.name:
f = open('/var/run/foo.pid','wb')
f.write(str(p.pid))
f.close()
