title: Python - Restart program automatically
body: <p>I am looking for restarting a program automatically, exactly if I was clicking on &quot;Run&quot; or &quot;F5&quot; to execute the program, when this one is already open.
  The idea would be to close the program, to start it again, but automatically.
  I found lot of similar questions, but nothing works very well, sometimes it opens a new window (with the background in black, over the console), and in this case (see code below) it starts again but with shell.
  For this program I would like that when it starts again, the program asks me the value of &quot;x&quot; I wish again, without opening an other window when reexecuting the program.</p>
  <p>Thanks for the help (I use Python 3.10.0 on Windows 10).</p>
  <pre><code>import os
  import sys
  import subprocess
  
  x=int(input(&quot;x = &quot;))
  
  if x==0:
  
  ##    subprocess.call([&quot;bash&quot;, &quot;-c&quot;, &quot;source ~/.profile; &quot; + &quot;test.py&quot;])
  
      os.execl(sys.executable, '&quot;{}&quot;'.format(sys.executable), *sys.argv)
  
  else:print(&quot;fin&quot;)
  </code></pre>