python - How to execfile an independent .py and continue on to next line of code in the original .py? -
i have 2 python files: 'old.py' , 'new.py'. execute 'new.py' 'old.py' using execfile("new.py"). however, rather waiting 'new.py' finish program before moving next line in 'old.py', both scripts continue independently (i.e., 'old.py' moves line after execfile('new.py') command immediately.
for instance, if 'new.py' takes 48 seconds complete program in entirety, , 'old.py' reads:
execfile("new.py") print 2+2
i "4" printed immediately, rather 48 seconds later.
how recommend doing this?
thank sharing knowledge , expertise.
you want utilize subprocess.popen
. open process in separate process.
# old.py - make sure it's chmod +x #!/usr/bin/python import time time.sleep(48)
# new.py #!/usr/bin/python import subprocess subprocess.popen(["./old.py"]) print(2+2)
>>> python new.py 4 >>> ps pid tty time cmd 2495 pts/17 00:00:00 bash 2696 pts/17 00:00:00 old.py 2697 pts/17 00:00:00 ps
Comments
Post a Comment