0

Looking for the best way of how a python script that I run in PyCharm can best call a second, indepent & new instance of the same script and then close the old instance. OS is Windows.

Background is that the script ocassionally produces a timeout, in which case I want to catch it via except and then restart it anew.

Looked at these two, but they are not what I want:

  1. subprocess.Popen('test.py', shell=True)

  2. os.system("python test.py")

  3. The new subprocess only seems to run for as long as the original script is still running.

  4. If I insert an "exit()" after calling the new script, then exit of the old instance would only execute after the full newly called script has run. As the script is an indefinite loop, this doesn't produce the needed result.

So the desired result is that the script is independently opened a second time, execution starts and then the old script will exit (while the new instance continues to run). Thanks for your help how to accomplish this!

  • I think you can play with `os.fork`, but why you want to do that? It would could cause zombie, and/or [orphaned process](https://superfastpython.com/orphan-process-in-python/). But here is an example [here](https://stackoverflow.com/questions/13095878/deliberately-make-an-orphan-process-in-python) – Wakeme UpNow Feb 13 '23 at 14:14

0 Answers0