#!/usr/bin/python
from subprocess import Popen
import sys
import time
import os
import signal
import subprocess

#filename1 = sys.argv[1]
#filename2 = sys.argv[2]
#filename3 = sys.argv[3]

#filename1 = sys.argv[1]
filename2 = sys.argv[1]
filename3 = sys.argv[2]

#print("\nStarting " + filename1)
#pro1 = subprocess.Popen("python3 " + filename1, stdout=subprocess.PIPE, 
        #shell=True, preexec_fn=os.setsid) 

while True:
    print("\nStarting " + filename2)
    # The os.setsid() is passed in the argument preexec_fn so
    # it's run after the fork() and before  exec() to run the shell.
    ##pro = subprocess.Popen("python3 " + filename + " --video videos/thesisfullbw.mp4", stdout=subprocess.PIPE, 
    ##                       shell=True, preexec_fn=os.setsid) 
    #pro1 = subprocess.Popen("python3 " + filename1, stdout=subprocess.PIPE, 
                           #shell=True, preexec_fn=os.setsid) 
    pro2 = Popen("python3 " + filename2, shell=True)
    #= subprocess.Popen("python3 " + filename2, stdout=subprocess.PIPE, 
                           #shell=True, preexec_fn=os.setsid) 
    #ime.sleep(60)
    ##os.killpg(os.getpgid(pro.pid), signal.SIGTERM)  # Send the signal to all the process groups
    pro2.wait()
    #pro2.kill()
    print("\nDone " + filename2)
    print("\nStarting " + filename3)
    pro3 = Popen("python3 " + filename3, shell=True)
   #= subprocess.Popen("python3 " + filename3, stdout=subprocess.PIPE, 
                           #shell=True, preexec_fn=os.setsid) 
    pro3.wait()
    #pro3.kill()
    print("\nDone " + filename3)

    #pro.wait()

    #p = Popen("python3 " + filename, shell=True)
    #time.sleep(10)
    #p.kill()
    #p.wait()
