From ee9b4016323ba0f7a773a5e014bc23bcf1a322cd Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Wed, 21 Sep 2011 13:01:58 +0200 Subject: [PATCH] Added a comment on who the is_important_traceback seems to work. It's only speculation --- flask/ext/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/flask/ext/__init__.py b/flask/ext/__init__.py index d030336f..86ad3da5 100644 --- a/flask/ext/__init__.py +++ b/flask/ext/__init__.py @@ -73,6 +73,20 @@ class _ExtensionImporter(object): something went wrong when the module was imported. (Eg: import of an import failed). """ + # Why can we access f_globals' __name__ here and the value is + # not None? I honestly don't know but here is my thinking. + # The module owns a reference to globals and the frame has one. + # Each function only keeps a reference to the globals not do the + # module which normally causes the problem that when the module + # shuts down all globals are set to None. Now however when the + # import system fails Python takes the short way out and does not + # actually properly shut down the module by Noneing the values + # but by just removing the entry from sys.modules. This means + # that the regular reference based cleanup kicks in. + # + # The good thing: At worst we will swallow an exception we should + # not and the error message will be messed up. However I think + # this should be sufficiently reliable. while tb is not None: if tb.tb_frame.f_globals.get('__name__') == important_module: return True