title: unordered output from python script
body: <p>I have a bash script that executes a python script like.</p>
  
  <pre><code>python script_name.py &gt;&gt; output.log 2&gt;&amp;1
  </code></pre>
  
  <p>As you can see I want standard output and std error in the same file called output.log.</p>
  
  <p>However, the script_name.py is executing a system command using os.system method. Let's assume following is the python script.</p>
  
  <pre><code>import os
  print('Executing python script')
  os.system('echo Helloworld')
  print('python script finished')
  </code></pre>
  
  <p>Now the output.log file is getting the output from the python script. But the output from os.system method is being logged first. So the output.log file is having the output as:</p>
  
  <pre><code>Helloworld
  Executing python script
  python script finished
  </code></pre>
  
  <p>But I want the print statement to be logged first.</p>
  
  <p>However, If I execute the script directly without the bash script. I get the following output in the console.</p>
  
  <pre><code>Executing python script
  Helloworld
  python script finished
  </code></pre>