Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sys.exitfunc not working in python

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
like image 758
Aniket Thakur Avatar asked Jul 20 '26 05:07

Aniket Thakur


1 Answers

sys.exitfunc is deprecated since python2.4 and was removed in python3.

like image 195
Bakuriu Avatar answered Jul 21 '26 19:07

Bakuriu