0

I am writing a script and got it to work run and did everything I wanted it to. I want to add in a function to have my dictionary sleep after checking it but when I add the time.sleep(5) <-(5 seconds) it now throws me this error

AttributeError: 'module' object has no attribute 'check_output'

On this line of code

 print ("INFO: checking kswapd number of process and cputime, check for TIME colume for how busy kswapd was" +  subprocess.check_output("ps -C kswapd0 -C kswapd1 -C kswapd2 -C kswapd3 -C kswapd4  -o pid,ppid,stime,etime,time,pcpu,args", shell=True))

Any one know how I could use Pipe and Popen to get around using subprocess.check_output?

Or here is where I put the time.sleep() if you see that its not the right for any reason

with open("/proc/meminfo") as f:
sample1 = []
for line in f:
    if line.startswith(pre):
        v = line.rsplit(None, 2)[1]
        sample1.append(v)
        time.sleep(5)

I am in Python v2.6, and no I cannot upgrade otherwise I would! Thanks for any input!

1
  • 1
    Did you call your python program subprocess.py by any chance? Is your indentation wrong on the question or in your program? The body of the code after the with should be indented. Commented Jul 20, 2015 at 13:16

2 Answers 2

3

You are using subprocess module from Python's standard library and this module indeed doesn't have an attribute check_output.

Assuming that you are using it like this:

import subprocess

child = Popen(["mycmd", "myarg"], stdout=PIPE)

you should call child.communicate()[0] and not subprocess.check_output() to see the output in Python 2.6.

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

2 Comments

What are you talking about? Perhaps you are using a very old version of Python.
@LtWorf OP says in the question that he is using Python 2.6 and can't upgrade. There's no check_output in subprocess module in Python 2.6. I indeed had a erroneously pasted .check_output() as it's absent on the Popen instance as well.
2

From the subprocess documentation :

output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]

4 Comments

Ho wait, maybe i didn't get all the question. Is it time.sleep(5) that throws you this error ?
yes it is. if I comment it out it works fine but when I keep it, it throws the error
This is weird... It should not happen. Are you sure that your install of python site-packages is not a downgrade of the Python2.7 or higher site-packages ?
Also are you sure there's not any errors in your import time ? (like another python file or whatever) I do not find anything about this message

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.