Discover more from Daily Dose of Data Science
An Elegant Way To Perform Shutdown Tasks in Python
Often towards the end of a program's execution, we run a few basic tasks such as saving objects, printing logs, etc.
To invoke a method right before the interpreter is shutting down, decorate it with the @𝐚𝐭𝐞𝐱𝐢𝐭.𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫 decorator.
The good thing is that it works even if the program gets terminated unexpectedly. Thus, you can use this method to save the state of the program or print any necessary details before it stops.
Read more: Documentation.
Share this post on LinkedIn: Post Link.
Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new and insightful about Python and Data Science every day. Also, get a Free Data Science PDF (250+ pages) with 200+ tips.
Find the code for my tips here: GitHub.