del behavior 2

"Martin v. Löwis" martin at v.loewis.de
Wed Jan 7 14:59:20 EST 2009


> I understand that and have seen it too.  That's fine.  But how do any
> of you deal with things that are left open because you did not get a
> chance to close them?  How do you clean up after the fact?  Do you
> simply keep track externally the things that need to be cleaned up if
> __del__ doesn't get a chance?  Any ideas?  Thanks

You should try to write you program so that any kind of process exit
will not need any cleanup. For many kinds of things, this will work
automatically on most file systems. For example, file handles and
network connections get automatically closed - so you don't absolutely
have to close them if your program exits abnormally. Likewise, database
connections will shut down properly, and windows will close just fine.

What kind of thing do you have that remains open even after the
process terminates?

Regards,
Martin



More information about the Python-list mailing list