Question

Very general question, but: does there exist a way to "globally" define a specific user input that will, no matter where it occurs - assuming predetermined raw_input points - restart the entire script?

Something that might allow for the statement "If at any point you wish you restart, enter 'restart'", as an example.

Thanks very much for any insight.

Was it helpful?

Solution

The traditional way to do what you want is to have the code listen for SIGHUP. The SIGHUP handler could restart the code as you want. A separate (possibly forked) process, with a user-friendly interface could be made to issue the signal on demand.

Information on writing python signal handlers can be found here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top