1

In my program, I have a config file which gets read on initialization and sets certain runtime variables. While the program is running a user can access and change these values in the config file through a menu I've created. Once these values have been modified I need the program to shut down and restart, so that it can run with the new config values.

I'm programming this in python and I am not sure how to go about doing this.

2
  • Please post your attempts so far to solve this problem, and then explain what the error with your code is. This website is not here to write code for you, it is to give you advice and help on code that you have already written but needs more work. Commented Jul 6, 2017 at 16:09
  • Just re-read the file again to get the new changes Commented Jul 6, 2017 at 16:11

2 Answers 2

1

You can either set a method to read the file for the new variables without restarting, or you can use

def restart_program():
    python = sys.executable
    os.execl(python, python, * sys.argv)

as mentioned in this question

Sign up to request clarification or add additional context in comments.

1 Comment

I would just reread and change the variables, if those vriables weren't passed to create objects that are running the rest of the program. But thank you for the code snippet, I'll give it a test and see if it works.
0

You can use sys.exit() to terminate the running process, but your best option is probably just to re-intialize/read files rather than terminating your code and restarting (i.e., you could call main() again). Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.