1

I am trying to run two python scripts in the third python script. The two python scripts got executed simultaneously without waiting for the execution of one script after the other.

I tried time.sleep(100) but it's not working.

        a1 = "a.py"
        b1 = "b.py"
        python_path = '/opt/dev_ai/bin/python'
        execution = subprocess.Popen([python_path,ml_path+a1,str(rule)])
        time.sleep(100)
        execution=subprocess.Popen([python_path,ml_path+scor+b1,str(rule)])

b1 started running before the completion of a1.

Divyank
  • 811
  • 2
  • 10
  • 26

3 Answers3

1

If you want to run several python files in just one python file you can first; Keep them in a same file or folder. Next you can type import 1stfile then import 2ndfile and you can add as many as you want. This only imports python files though

ScamperedC
  • 45
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 04 '22 at 14:29
0

Check the return code of the subprocess1 and if it is okay, execute the second subprocess.

How to get exit code when using Python subprocess communicate method?

Devang Sanghani
  • 731
  • 5
  • 14
0

That's subprocess starts asynchronous processes, to make this synchronous check out this thread

Emilio
  • 102
  • 11
RaiBnod
  • 2,141
  • 2
  • 19
  • 25