["python","windows","python-2.7"]
Check if a process is running or not on Windows?

I am trying to create a python script which I will later run as a service. Now I want to run a particular part of the code only when iTunes is running. I understand from some research that polling the entire command list and then searching for the application for that list is expensive. I found out that processes on UNIX-based operating systems create a lock file to notify that a program is currently running, at which point we can use os.stat(location_of_file) to check if the file exists to determine if a program is running or not. Is there a similar lock file created on Windows? If not what are the various ways in Python by which we can determine if a process is running or not? I am using python 2.7 and iTunes COM interface.
I found psutil very slow. A much more performant solution: import win32gui window_titles = set() def winEnumHandler( hwnd, ctx ): if win32gui.IsWindowVisible( hwnd ): window_titles.add(win32gui.GetWindowText( hwnd ) ) win32gui.EnumWindows( winEnumHandler, None ) print(window_titles)