In some conditions (typically with threads, __del__ methods, etc) the\ncleanup mechanism of Python gets in trouble and some exceptions are\nnot raised but just printed on stderr.\nI have an application using Paste and when I run the tests I get some\nannoying\nignored exceptions during cleanup. Running the code with the -v option\nI get things\nlike that:\n\n<snip lots of other stuff>\n# cleanup sqlalchemy.util\n# cleanup sqlalchemy.sql.expression\n# cleanup symbol\n# cleanup urllib2\n# cleanup sqlalchemy.orm.query\n# cleanup smweb.config\n# cleanup formencode\n# cleanup smweb.config.environment\nException exceptions.TypeError: "'NoneType' object is not callable" in\n<function <lambda> at 0x26861b8> ignored\nException exceptions.TypeError: "'NoneType' object is not callable" in\n<function <lambda> at 0x2598578> ignored\n# cleanup dbhash\n# cleanup xmlrpclib\n# cleanup mako.pygen\n# cleanup time\n# cleanup paste.util.import_string\n# cleanup sys\n# cleanup __builtin__\n# cleanup ints: 5096 unfreed ints in 145 out of 171 blocks\n# cleanup floats: 43 unfreed floats in 3 out of 4 blocks\n\nAs you see, the exceptions happen during the cleanup of\nsmweb.config.environment,\nwhich the part of code I wrote, but which has no obvious problems and\nimports\n*lots* of other stuff. Is there some way to hook in the cleanup\nmechanism, start\na pdb and see really what is happening? I tried to trace the execution\nflow with the\ntrace module but without success. There is so much code there that I\nam unable\nto track down the source of the problem. I suspect there is some\n__del__ method\nsomewhere that tries to call a function which has been set to None by\nthe cleanup\nmechanism, possibly from another thread, but I cannot find it. How am\nI supposed to\ndebug such things?