I am trying to run following simple code
import sys
print("Starting Test Python Module");
def testmethod():
print("From test method")
sys.exitfunc = testmethod
print("Terminating Test Python Module");
and it prints
C:\Users\athakur\Softwares>python test.py
Starting Test Python Module
Terminating Test Python Module
I am not able to understand why it does not print "From Test method"
Using atexit works fine though
import atexit
print("Starting Test Python Module");
def testmethod():
print("From test method")
atexit.register(testmethod)
print("Terminating Test Python Module");
Outputs
C:\Users\athakur\Softwares>python test.py
Starting Test Python Module
Terminating Test Python Module
From test method
sys.exitfunc is deprecated since python2.4 and was removed in python3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With