次の簡単なコードを実行しようとしています
import sys
print("Starting Test Python Module");
def testmethod():
print("From test method")
sys.exitfunc = testmethod
print("Terminating Test Python Module");
そしてそれは印刷します
C:\Users\athakur\Softwares>python test.py
Starting Test Python Module
Terminating Test Python Module
「From Test method」が出力されない理由がわかりません
ただし、 atexit を使用しても問題なく動作します
import atexit
print("Starting Test Python Module");
def testmethod():
print("From test method")
atexit.register(testmethod)
print("Terminating Test Python Module");
出力
C:\Users\athakur\Softwares>python test.py
Starting Test Python Module
Terminating Test Python Module
From test method