Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top