#NEWLINE# def pidof( pgname ) : #NEWLINE# #INDENT# pids = [ ] #NEWLINE# for proc in psutil . process_iter ( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# name = proc . name ( ) #NEWLINE# #UNINDENT# except psutil . Error : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( name == pgname ) : #NEWLINE# #INDENT# pids . append ( str ( proc . pid ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# cmdline = proc . cmdline ( ) #NEWLINE# #UNINDENT# except psutil . Error : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmdline and ( cmdline [ 0 ] == proc ) ) : #NEWLINE# #INDENT# pids . append ( str ( proc . pid ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return pids