473,382 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Re: Gracefull application exit.

Robert Rawlins wrote:
I’m looking to implement an exit/termination process for an application
which can be triggered by A) a keyboard interrupt or B) termination of
the application as a Daemon using a signal.

I have a whole bunch of tasks I want to perform as a cleanup before the
application is terminated, cleaning files, database calls, closing open
connections and a few other things.

I know we have:

# I'm the main application started method.

if __name__ == /"__main__"/:

For starting an application, but do we have an equivalent methods for
when an application is terminated which we can use to close down any
current internal processes before the application exits?

I’d really love to have your thoughts and experience on gracefully
killing an application.
You want to look at the atexit module:

http://docs.python.org/lib/module-atexit.html

but mind the caveats:

"""
Note: the functions registered via this module are not
called when the program is killed by a signal, when a
Python fatal internal error is detected, or when
os._exit() is called.
"""

TJG

Jul 24 '08 #1
0 1766

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Guinness Mann | last post by:
Pardon me if this is not the optimum newsgroup for this post, but it's the only .NET newsgroup I read and I'm certain someone here can help me. I have a C# program that checks for an error...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
4
by: Bob Day | last post by:
Using VS 2003, VB.net... I am confused about the Application.Exit method, where the help states "This method does not force the application to exit." Aside from the naming confusion, how do I...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
2
by: Susan Baker | last post by:
Hi, I am writing a Win32 DLL. I want to be able to handle any SEGVs (segmentation violations) gracefully, by using an error handler of sorts. Currently, if a user of my DLL (typically a VB...
1
by: =?Utf-8?B?VGFvZ2U=?= | last post by:
Hi All, When I use applcation.exit() in winForm application, the form closed, but the process is still going!! ( The debug process is still running if debug in VS IDE). Environment.Exit(0) works...
1
by: gauss | last post by:
Hi all, I have a problem and I wanted to solve it :-). My problem is I have an application (under GNU/Linux) wich launches a thread, executes some code and collects some statistics. My problem...
0
by: Robert Rawlins | last post by:
but mind the caveats: Thanks Tim, the main caveat which worries me is the fact that it doesn't get called when being killed by SIGTERM. When I look at implementing the application as Daemon will...
0
by: M.-A. Lemburg | last post by:
On 2008-07-24 18:06, Robert Rawlins wrote: Warp your whole application into a main() function and then use: try: main() finally: cleanup() --
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.