Let call this zombie pidfile. I encoutered this issue when process was killed or somehow terminated but pidfile prevailed.
In this case when new process try to find process by PID from pidfile using cmd1 = psutil.Process(pid).cmdline()[0] it crashes on IndexError because no process is not found thus indexing over empty list = crash.
Proposed solution is to add IndexError into try-except block and then overwrite existing pidfile with current PID.
Let call this zombie pidfile. I encoutered this issue when process was killed or somehow terminated but pidfile prevailed.
In this case when new process try to find process by PID from pidfile using
cmd1 = psutil.Process(pid).cmdline()[0]it crashes onIndexErrorbecause no process is not found thus indexing over empty list = crash.Proposed solution is to add IndexError into try-except block and then overwrite existing pidfile with current PID.