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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top