I tried to understand why this is happening. I call the command to reboot the network on an Ubuntu 12.04 server.
Fast execution
When I invoke a command using one of the following three methods, it takes about 0.1 second to execute:
- directly in the terminal
- python script using
os.system - python script using
subprocess.call
terminal session:
root@ubuntu :~
Slow execution
However, if I use subprocess.check_output or Popen and try to read the output, it takes 23 seconds. The path is slower. This seems to be a dramatic difference only when I try to use a function that will return the output commands. I would like to understand why this is happening, and find a solution to execute this command and get its output without taking so much time.
terminal session:
root@ubuntu :~
Update
One of the comments suggested trying the tee team. Results that are very interesting. In a terminal without python, if tee is used, it takes the same 23 seconds. I'm still wondering why, but at least it can provide more information about what is going on.
root@ubuntu :~
Marwan alsabbagh
source share