Skip to content

'cmd1 = psutil.Process(pid).cmdline()[0]' with IndexError: list index out of range #8

@zhaopan-vip

Description

@zhaopan-vip

Exception:

File "... /pidfile/pidfile.py", line 29, in is_running
   cmd1 = psutil.Process(pid).cmdline()[0]
IndexError: list index out of range

This occurs when process been killed, with pidfile not removed...
Then next time run it, the exception happens...

Should we change the cmdline check with code below?

        try:
            cmdline = psutil.Process(pid).cmdline()
            if not cmdline:
                return False
            cmd1 = cmdline[0]
            return cmd1 == self._process_name
        except psutil.AccessDenied:
            return False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions