1
subprocess.check_output('lspci | egrep  -i "virtio network" | wc -l', shell=True)

Is failing with exit status -15. What could be the possible scenarios for this to happen?

CalledProcessError: Command 'lspci | egrep  -i "virtio network" | wc -l' returned non-zero exit status -15

I read about exit status 1 but what is the specific meaning behind code -15.

3
  • Can you run that in your command line? Try running it in the command line and do a $ echo $? after it to look at the return value and see if it is the same. Commented Sep 12, 2018 at 6:35
  • Your command works fine in Ubuntu 18 (Python3). What is the environment where the error occurs? Commented Sep 12, 2018 at 9:18
  • @Hannu It's non-reproducible. It happened in production environment. VM was on GCP. Commented Sep 12, 2018 at 11:57

1 Answer 1

1

You would see this in python 2, if the the subprocess died having received SIGTERM (i.e. 15). Since you've used shell=True, this mean the /bin/sh process wrapping your call got killed with (received signal) SIGTERM (and terminated).

Python 3 output would be perhaps a bit more helpful as to hinting the cause in this case:

subprocess.CalledProcessError: Command 'lspci | egrep  -i "virtio network" | wc -l' died with <Signals.SIGTERM: 15>.

Looking at your line:

subprocess.check_output('lspci | egrep  -i "virtio network" | wc -l', shell=True)

Perhaps it would make sense to try this:

len([l for l
     in subprocess.check_output('lspci').lower().splitlines()
     if b"virtio network" in l])

Instead of wrapping the call in a shell instance and forking multiple processes to get number of lines with certain string, it retrieves output from lspci, converts it to lower case (to make the matches case insensitive like -i above) and splits the output on line boundaries. List comprehension based on the list of those lines gets us a resulting list of all lines limited to those containing the searched for str (or rather bytes to be py2/3 friendly) and len gives us an int of how many such lines there were.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.