title: How to execute some python statements after executing external shell commands
body: <p>I'm developing a Django application and it uses FFMPEG. Basically it receives a video uploaded by the user and it uses FFMPEG to transcode it to 240p, 360p and 480p. Since this is server-side code, many users might upload at the same time. Also after transcoding, records are added into a database table.</p>
  <pre><code>out=&quot;media/uploads/&quot;+folder #This is the upload path where folder is the name of the video
  
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
  command = &quot;ffmpeg -i '&quot;+os.path.join(BASE_DIR,out)+&quot;/&quot;+fname+&quot;' -s 426x240 '&quot;+os.path.join(BASE_DIR,out)+&quot;/240p.mp4'&quot;
  subprocess.call(command,shell=True)
  convert = Convert.objects.get_or_create(vid=rec,name=&quot;240p.mp4&quot;,video=str(out+'/240p.mp4'))
  
  command = &quot;ffmpeg -i '&quot;+os.path.join(BASE_DIR,out)+&quot;/&quot;+fname+&quot;' -s 640x360 '&quot;+os.path.join(BASE_DIR,out)+&quot;/360p.mp4'&quot;
  subprocess.call(command,shell=True)
  convert = Convert.objects.get_or_create(vid=rec,name=&quot;360p.mp4&quot;,video=str(out+'/360p.mp4'))
  
  command = &quot;ffmpeg -i '&quot;+os.path.join(BASE_DIR,out)+&quot;/&quot;+fname+&quot;' -s 854x480 '&quot;+os.path.join(BASE_DIR,out)+&quot;/480p.mp4'&quot;
  subprocess.call(command,shell=True)
  convert = Convert.objects.get_or_create(vid=rec,name=&quot;480p.mp4&quot;,video=str(out+'/480p.mp4'))
  </code></pre>
  <p>As this code will be run on a server, multiple users might upload videos at the same time. I want this code to run without any problems in that scenario. Also the database operations must be executed only after the FFMPEG commands have been executed.</p>
  <p>What are the changes that must be done to this code?</p>