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.
Find the code for my tips here: GitHub.
I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn.