1

I have a python script. Which is running as a service with a while loop for ever. The script need to be executed by another python but without waiting for the out put it should pass through.

So the main script with while loop is as follows "main.py". Which never going to be end.

while True:
    # do some task
    time.sleep(5)

This need to be executed by another python "start.py" with similar function as follows.

os.system("main.py 1")

OR

subprocess.Popen("python main.py")

Problem here "start.py" won't finish as witing for the out put of "main.py". But I want to make it like "start.py" need to load "main.py" and leave it in background. Then the "start.py" need to complete the process. How can I modify the

os.system("main.py 1")

function to skip the waiting for "main.py"? Please consider this need to run on cross platform.

sugunan
  • 4,408
  • 6
  • 41
  • 66

1 Answers1

0

I recommend for you to check out Plumbum https://plumbum.readthedocs.org/en/latest/ specifically the section on background/foreground https://plumbum.readthedocs.org/en/latest/#foreground-and-background-execution

from plumbum import BG
from plumbum.cmd import python

python('main.py', '1') & BG

Cross platform also.

dalore
  • 5,594
  • 1
  • 36
  • 38