Daily Dose of Data Science

Share this post

An Elegant Way To Perform Shutdown Tasks in Python

www.blog.dailydoseofds.com

An Elegant Way To Perform Shutdown Tasks in Python

Avi Chawla
Jan 4, 2023
Share

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.

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.

Share
Previous
Next
Comments
Top
New
Community

No posts

Ready for more?

Β© 2023 Avi Chawla
Privacy βˆ™ Terms βˆ™ Collection notice
Start WritingGet the app
SubstackΒ is the home for great writing