You don't need to launch another interpreter.
You can simply execute the code from the other script in a separte thread or process.
Refactor your "other" script
You want your "other" script to be callable from another script. To do so, you'll just need a function that does what your script used to do.
#other.py
def main(arg1, arg2, arg3):
do_stuff(arg1, arg2)
more_stuff(arg2, arg3)
other_stuff(arg1, arg3)
finish_stuff(arg1, arg2, arg3)
Execute the code in another thread
In your main script, when you want to execute the code from other.py
, start a new thread:
#script.py
from threading import Thread
from other import main
thread = Thread(target = main)
thread.start() # This code will execute in parallel to the current code
To check that whether your work is done, use thread.is_alive()
. To block until it finishes, use thread.join()