A Monday 20 July 2009 09:44:09 Francesc Alted escrigué: > This message bounced (perhaps sent from unsubscribed address). > > ------------------------------------------------------- > From: Dav Clark <davcl...@berkeley.edu> > To: pytables-users@lists.sourceforge.net > Date: Friday 23:40:25 > > > Hi, > > > > I have a program that uses pytables, and I was wondering if I could > > get a pointer to where in the code you deal with exit handling. for > > example, when a program crashes, I get a message like the following: > > > > Closing remaining open files: testing02/raw_pressure.h5... done > > > > I'd like to be able to customize this behavior, as well as perhaps > > copy this functionality for other parts of my code. > > The responsible of this behaviour is the tables.file.close_open_files() > function that is being registered via atexit.register() Python function. > Although you can't de-register already registered cleanup functions, you > can register new ones to tailor the existing behaviour. For example, if > you register this one: > > def my_close_open_files(verbose): > open_files = tb.file._open_files > are_open_files = len(open_files) > 0 > if verbose and are_open_files: > print >> sys.stderr, "Closing remaining open files:", > for fileh in open_files.keys(): > if verbose: > print >> sys.stderr, "%s..." % (fileh.filename,), > fileh.close() > if verbose: > print >> sys.stderr, "done", > if verbose and are_open_files: > print >> sys.stderr > > import sys, atexit > atexit.register(my_close_open_files, False) > > then, you won't get the closing messages anymore because the new registered > function is executed before the existing one. If you want the messages > back again, just set the verbose parameter to true.
I've added this as a basic tip in the ``UserDocuments`` page: http://pytables.org/moin/UserDocuments/AtexitHooks Feel free to update the page if you want to. Also, I've taken the opportunity to give the ``UserDocuments`` page more visibility (it is accessible now in the navigation bar of the wiki). -- Francesc Alted ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Pytables-users mailing list Pytables-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pytables-users