Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 574305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:48:59+00:00 2026-05-13T13:48:59+00:00

I’m writing a Python program that, if the user changes settings while running it,

  • 0

I’m writing a Python program that, if the user changes settings while running it, needs to be restarted to apply the changed settings. Is there a way of doing this? I’m thinking something along the lines of:

import sys
command_line = ' '.join(sys.argv)
# Now do something with command_line
# Now call my custom exit procedure

Note: I’m on Windows, if that makes a difference

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:48:59+00:00Added an answer on May 13, 2026 at 1:48 pm

    I would bypass all the angst you’re likely to get from trying to re-run yourself and leave it in the hands of the environment.

    By that, I mean:

    1. Have a controlling program which does nothing more than run your program (with the same parameters it was given) in a loop while your program exits with a specific “restart” code. This could be as simple as a cmd file or as complex as another (very simple) Python program that uses os.system). Basically, as long as the controlling program gets the code “restart”, it will re-run your program with exactly the same parameters. Any other code will cause it to exit with that code.

    2. When you want to exit fully, have your real Python program exit with return code 0 (or anything that’s not the “restart” code in an error situation).

    3. If you just want to cycle to another iteration of your program (to re-read the config for example), exit with the “restart” code recognised by the controlling program.

    But you may also want to think about re-engineering your application so that it can re-read its configuration at any time. This will make the whole problem go away. You don’t mention why that’s not an option so I’m assuming you have some reason why it won’t work.

    But, if you don’t, that’s the path I’d be choosing.

    To provide some sample code for the first option (this is on Windows but under Cygwin – the same basic rules should apply for Windows native Python but you should check the return values from os.system).:

    > cat phase1.py
    #!/usr/bin/python
    import os
    status = 9
    while status == 9:
        status = int(os.system ("./phase2.py") / 256) # exit code is upper 8 bits
        print "Controller: %d"%(status)
    

     

    > cat phase2.py
    #!/usr/bin/python
    import sys
    import time
    time.sleep(1)
    val = int(time.time())%10
    if val == 0:
        rc = 0
    else:
        rc = 9
    print "Program: %d -> %d"%(val,rc)
    sys.exit(rc)
    

     

    > ./phase1.py
    Program: 2 -> 9
    Controller: 9
    Program: 3 -> 9
    Controller: 9
    Program: 4 -> 9
    Controller: 9
    Program: 5 -> 9
    Controller: 9
    Program: 7 -> 9
    Controller: 9
    Program: 8 -> 9
    Controller: 9
    Program: 9 -> 9
    Controller: 9
    Program: 0 -> 0
    Controller: 0
    

    You can see the controller using an exit code of 9 to decide whether to re-run the program. The program itself is a dumb one which returns 9 unless it’s on a 10-second multiple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Before you start using any service, it's generally a good… May 16, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer The problem ended up being the Dictionary class, I got… May 16, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer HTTP (RFC2616) spec states that everything other than the scheme… May 16, 2026 at 5:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.