0

Here is the Code :

def restartSim():
        """Restarts the current program.
        Note: this function does not return. Any cleanup action (like
        saving data) must be done before calling this function."""
        python = sys.executable
        os.execl(python, python, * sys.argv)

This code will work perfectly fine in python 3.6 but in python 2.7.

How do i restart in python 2.7?

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
nrs
  • 937
  • 3
  • 17
  • 42
  • Possible duplicate of [Restart python-script from within itself](https://stackoverflow.com/questions/11329917/restart-python-script-from-within-itself) – Tim Klein Mar 29 '19 at 11:21
  • @TimKlein Its not working in python 2.7... Can u post code please for python 2.7 – nrs Mar 29 '19 at 11:30
  • What error are you seeing? What alternatives have you tried? – Tim Klein Mar 29 '19 at 11:33
  • @TimKlein I am not getting any error...I tried def restart(self): self.shutdown() chdir(owd) # close some open fds for i in range(3,50): try: close(i) except : pass execl(executable, executable, *sys.argv) _exit(0) – nrs Mar 29 '19 at 12:40

0 Answers0