My Python program takes a long time to run, but sometimes I don't want to wait until the program is complete to modify the parameters, can you modify the source code while the program is executing, and then execute the new program? I don't know if this is feasible.
Reply content:
Have an effect, but very small.
The running program itself is not affected because it was automatically compiled into Python bytecode and ran in memory before it was run. Unless you call reload () in the program to reload the program, it will not affect the operation.
However, if the program has an error and throws an exception, it immediately reads from the current my Python source file and displays an error line. So the exception stack shows the running program error line number, as well as the current version of the latest source code. Looks a little split. You should use the command line arguments instead of modifying the program ... Then why do you want to put the parameters in the main py file?
Can't you write another file to set your parameters?
Check this parameter file periodically (e.g. Ini,csv,json)
Then change the program execution strategy. Also write a script to change the normal operation to first copy and then run, can you change the parameters in a multi-threaded way? Not very understanding. For this and the future operation, will not.
Remember to see @kyon N is an interesting answer,http//zhihu.com/question/39837216/answer/83451305