Problem with __del__ (thanks)
Andrew Dalke
dalke at acm.org
Wed Jan 10 13:36:31 EST 2001
Stephan Effelsberg wrote:
>I want to (have to!)
>reinitialize the hardware if the program exits in an unusual way (e.g.
>keyboard interrupt), and I thought using the destructor
> of the controlling
>class to do this job would be the proper way.
Put your top level code inside of a try/except block:
if __name__ == "__main__":
try:
main()
except:
# something unexpected happened so reinit the hardware
reinitialize()
raise
The call to reinitialize() will be done before Python does
its cleanup so there will be no problems because of that.
Andrew
dalke at acm.org
More information about the Python-list
mailing list