質問

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