> In a function of the class, I have put the code in try/except block. > > try: > ---------- > ---------- > except AssertionError: > print "Error Condition" > > In this code, when error occurs, it raises the AssertionError > but the destuctor isnt called itself.
The destructor will only get called if the object is destroyed. The object will be destroyed once all references to it are broken either by it moving out of scope (eg exiting a function/method) or by you del()'ing it sufficient times to reduce its reference count to zero.. > As a result the ssh conenctions are not closed. > What is the general way a python script exits on encountering an > error? raise SystemError or call sys,.exit() will exit completely. But a try/finally (as opposed to a try/except) will also be useful to guarantee execution of a block of code that can tidy up things like open sockets/files etc. HTH, Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor