Home > front end >  How do I make my script stop and start again in the same line?
How do I make my script stop and start again in the same line?

Time:05-23

So basically I am running a script in Python that executes other 5 .py scripts as well, just like this:

exec(open('statcprs.py').read())
exec(open('dragndownf.py').read())
exec(open('lowprbubble.py').read())
exec(open('wshearstr.py').read())
exec(open('slices.py').read())

These .py files uses Paraview (another software) to run some stuff, so If I only run "statcprs.py", it will open Paraview's terminal and run the script. The problem is, from the first one "statcprs.py" to the second one "dragndownf.py" it doesn't interrupt the software, and it continue running it, interefering with scripts from both .py files.

I would like to execute the first one, stop and then start the second one from scratch without connection between them. is this somehow possible?

I think the problem is this line (line 1) which opens the terminal:

#!/usr/bin/env pvpython

CodePudding user response:

The following will execute a list of python scripts in the same folder as the driver script:

import os
from pathlib import Path
import subprocess
import sys

scripts = [
    'statcprs.py',
    'dragndownf.py',
    'lowprbubble.py',
    'wshearstr.py',
    'slices.py',
]

parent = Path(__file__).resolve().parent

for script in scripts:
    script_path = parent / script
    subprocess.call([sys.executable, script_path])
  • Related