Search code examples
pythoncimaprestart

Python restart script in another cmd's window


is there a way to restart another script in another shell? i have script that sometimes stuck waiting to read email from gmail and imap. from another script i would like to restart the main one but without stopping the execution of the second i have tried:

os.system("C:\Users\light\Documents\Python\BOTBOL\Gmail\V1\send.py")
process = subprocess.Popen(["python", "C:\Users\light\Documents\Python\BOTBOL\Gmail\V1\send.py"])

but both run the main in the second's shell EDIT: sorry, for shell i mean terminal window


Solution

  • After your last comment and as the syntax show that you are using Windows, I assume that you want to launch a Python script in another console. The magic word here is START if you want that the launching execute in parallel with the new one, or START /W if you want to wait for the end of the subprocess.

    In your case, you could use:

    subprocess.call(["cmd.exe", "/c", "START", "C:\Path\To\PYTHON.EXE",
        "C:\Users\light\Documents\Python\BOTBOL\Gmail\V1\send.py"])