0

I have two python scripts out of which one of them does some processing from the data in a excel file. The second script is used to update the data whenever the user updates the excel. After the user modifies the xlsx file he/she can run the second script and it automatically reloads the second script. However the problem here is that since the first script that does the actual processing is having a infinite while loop and when I am executing the file from the second script it doesn't exit after executing the first py file. I just want the second script to execute the first python file once and then exit out while the first script keeps executing infinitely. Here is the code:

import notification
import importlib
import subprocess
import os
import sys

importlib.reload(notification)
if os.name == 'nt':
    subprocess.run(["python","notification.py"], capture_output=True)
else:
    subprocess.run(["python3","notification.py"], capture_output=True)
sys.exit(0)

Here the name of my first file is notification.py.

1 Answers1

0

You need to use subprocess.Popen instead of subprocess.run

Reference:

Python spawn off a child subprocess, detach, and exit

https://docs.python.org/3/library/subprocess.html#popen-objects

prehistoricpenguin
  • 6,130
  • 3
  • 25
  • 42