This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients brett.cannon, martin.panter, pitrou
Date 2014-09-18.04:59:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1411016387.42.0.531094778863.issue21049@psf.upfronthosting.co.za>
In-reply-to
Content
My original demonstration was distilled from a real world case. I get this issue with other real world cases too, so I am expanding the title to reflect what I think is going on. This problem seems to be caused by a ResourceWarning triggered from a garbage cycle being freed just before Python exits. The flood of ImportWarning lines makes it annoying to scroll up to see what other ResourceWarning messages, exceptions, etc you are missing out on.

Much simpler one-liner demonstration adapted from Message 222403 (because class definitions create garbage cycles in my experience):

python3 -Wall -c 'class C: a = open("/dev/null")'

The best workaround is probably to use “python -Wdefault” rather than “python -Wall”. Then you only get one ImportWarning line.

I suspect the problem might be caused by a recursive loop between emitting a warning and importing something, as Antoine hinted. Calling sys.setrecursionlimit(30) reduces the flood to 5 lines. Unfortunately my modifications to “importlib/_bootstrap.py” and “warnings.py” on my OS are not having any effect, otherwise I might try to make a patch.

Perhaps if it is not appropriate for the ImportWarning to be removed, could the code printing out the warning be changed to avoid triggering it in the first place?
History
Date User Action Args
2014-09-18 04:59:47martin.pantersetrecipients: + martin.panter, brett.cannon, pitrou
2014-09-18 04:59:47martin.pantersetmessageid: <1411016387.42.0.531094778863.issue21049@psf.upfronthosting.co.za>
2014-09-18 04:59:47martin.panterlinkissue21049 messages
2014-09-18 04:59:46martin.pantercreate