Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'warnings': 0.04; 'subject:Python': 0.06; 'assuming': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'record.': 0.09; 'subject:into': 0.09; 'python': 0.11; 'garbage': 0.16; 'message-id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:Convert': 0.16; 'subject:exception': 0.16; 'exception': 0.16; '(not': 0.18; 'mechanism': 0.19; 'header :User-Agent:1': 0.23; 'error': 0.23; 'daniel': 0.26; 'header:X -Complaints-To:1': 0.27; 'tried': 0.27; 'correct': 0.29; 'raise': 0.29; "doesn't": 0.30; 'exceptions': 0.31; 'prints': 0.31; 'writes:': 0.31; 'guess': 0.33; '"the': 0.34; 'created': 0.35; 'there': 0.35; 'module.': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'turn': 0.37; 'being': 0.38; 'to:addr:python- list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'users': 0.40; 'most': 0.60; 'new': 0.61; 'such': 0.63; 'taking': 0.65; 'answer.': 0.68; 'gathering': 0.68; 'skip:w 30': 0.69; 'collection.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Piotr Dobrogost Subject: Re: Convert Python 3 ResourceWarnings into exception Date: Thu, 31 Jul 2014 08:54:43 +0000 (UTC) References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 195.117.20.144 (Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406796903 news.xs4all.nl 2881 [2001:888:2000:d::a6]:37484 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75406 Terry Reedy udel.edu> writes: > > python -W error ... > "Raise an exception instead of printing a warning message." > > You can also turn this on with the warnings module. Assuming that this > works for ResourceWarning, which is should, please correct the SO record. Thanks for taking time to answer. Please notice that OP already tried warnings.simplefilter(action='error', category=ResourceWarning) with no luck. Also, in the answer, Daniel states the following: "The ResourceWarning is indeed being generated during garbage collection, and Python prints a message because it doesn't have a way to raise an exception at that point." If it were true that would have been rather unfortunate as I guess most ResourceWarnings are being generated during garbage collection. In that case to let users get hold on such warnings there would need to be created new mechanism for gathering warnings (not based on exceptions as a mean of transport).