[Tutor] Running multiple python scripts from one python scripts

ose micah osaosemwe at yahoo.com
Thu Oct 24 14:23:47 EDT 2019


 Hello Alan, 
I have not fully solved the problem. I have a temporary fix, which is using time and subprocess which works e.g. I used time, because the processes happens to run almost simultaneously.
import fileinputimport osimport sysimport timeimport subprocess as sp...............# running the scripts in processesextProc1 = sp.Popen([sys.executable, '/tmp/delete_line3.py'],  stdout=sp.PIPE)time.sleep(5)extProc2 = sp.Popen([ sys.executable, '/tmp/create_20lines.py'], stdout=sp.PIPE)time.sleep(5)extProc3 = sp.Popen([sys.executable,'/tmp/ delete_ON2_.py'], stdout=sp.PIPE) time.sleep(5)
extProc = sp.Popen([sys.executable,'/tmp/ create_50.py'], stdout=sp.PIPE) time.sleep(5)

# closing the parent version of the pipesextProc1.close()extProc2.close()
extProc3.close()
extProc4.close()

# Waiting for the program to completeextProc1.wait()extProc2.wait()
extProc3.wait()
extProc4.wait()

This happens to work for me. If any have a better solution, please share.
Thanks and regards,
Ose Osamudiamen. 


    On Thursday, October 24, 2019, 09:35:24 AM EDT, ose micah <osaosemwe at yahoo.com> wrote:  
 
 Hello Alan,
I am having issues in running multiple python scripts in one same program. The reason is that, I am creating this mini scripts in the main (master) scripts, then at the end run them all sequentially. 
here is a sample. 



import osimport sys...............os.system('python /tmp/delete_line3.py')os.system('python /tmp/create_20lines.py')os.system('python /tmp/delete_ON2_.py')os.system('python /tmp/create_50.py')

when I tried this, only the first script "delete_line3.py" ran and quitted. The rest did not execute.
Next I tried this program.
import fileinputimport subprocess as sp............... extProc = sp.Popen(['python','/tmp/delete_line3.py'])sp.Popen.terminate(extProc)extProc = sp.Popen(['python','/tmp/create_20lines.py'])sp.Popen.terminate(extProc)extProc = sp.Popen(['python','/tmp/ delete_ON2_.py'])sp.Popen.terminate(extProc)extProc = sp.Popen(['python','/tmp/ create_50.py'])sp.Popen.terminate(extProc)

it did not work at all.
is there anything that I can do to 


Thanks and regards,
Ose Micah.


  


More information about the Tutor mailing list