Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'python,': 0.02; 'output': 0.05; 'back.': 0.09; 'exception,': 0.09; 'oh,': 0.09; 'postgresql,': 0.09; 'rewrite': 0.09; 'scripts,': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'changes': 0.15; '"alter': 0.16; '(written': 0.16; 'example)': 0.16; 'exception?': 0.16; 'exceptions,': 0.16; 'fetches': 0.16; 'hmm.': 0.16; 'script,': 0.16; 'scripts.': 0.16; 'stderr': 0.16; 'stuff,': 0.16; 'wary': 0.16; 'exception': 0.16; 'appropriate': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'all,': 0.19; 'commit': 0.19; 'thanks.': 0.20; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'file.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'sort': 0.25; 'script': 0.25; 'handling': 0.26; '(for': 0.26; 'developing': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'patch': 0.29; "doesn't": 0.30; 'errors': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'catching': 0.31; 'end,': 0.31; 'terminate': 0.31; 'covered': 0.32; 'critical': 0.32; 'run': 0.32; 'another': 0.32; 'problem': 0.35; 'transaction': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'disk': 0.36; 'most': 0.60; 'august': 0.61; 'till': 0.61; 'full': 0.61; 'simply': 0.61; 'simple': 0.61; 'soon': 0.63; 'our': 0.64; 'more': 0.64; '(that': 0.65; 'articles': 0.65; 'talking': 0.65; 'to:addr:gmail.com': 0.65; 'it!': 0.67; 'skill': 0.68; 'safe': 0.72; 'integrity': 0.74; '"real': 0.84; 'usage.': 0.84; 'error;': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=rbMqHZ0Oc43EovwnSddVdELNsO5p2b81i+d/DTpMb3k=; b=CFxbxu9yDbQrtCtnImlKv6C0lB7b1cEBoYWvLdLtqzar2R922y3BuODyKKPdLOS1G1 dYWmykI84z3bZ4Lt61tTYnxIMge7tzUUTJMdCKcYwXzpezfDOETftCVQhwtyJ6UuW8ho mwEhis2fnV15djpwfKiDU7f0z9iyFatSxHzL209yUf/Pb4RnDyizenhSRA01I3jtecaX eDSGIRgN7F/4zbJPkyPsKlnvLHFlADLz9TBvmqtAxMXrBoYpaIA9QjVpobMiUvUJ4P+9 4x/kSj0r3UjYz/8WPFsNBOu3CH6zbdJzmCSiQF8rxTtiKS7bFUI7FRDytUh1D/6BvaYI kRqA== MIME-Version: 1.0 X-Received: by 10.224.126.129 with SMTP id c1mr2052639qas.93.1377785498497; Thu, 29 Aug 2013 07:11:38 -0700 (PDT) In-Reply-To: References: Date: Thu, 29 Aug 2013 11:11:38 -0300 Subject: Re: Interface and duck typing woes From: Joe Junior To: Chris Angelico Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377785505 news.xs4all.nl 15978 [2001:888:2000:d::a6]:60896 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53247 On 29 August 2013 10:07, Chris Angelico wrote: > Hmm. l don't know of any good articles off-hand. But what I'm talking > about is simply developing the skill of reading exceptions, plus a few > simple things like knowing where it's appropriate to catch-and-log; > sometimes, what that means is actually writing some code to (for > example) email you whenever there's an exception, but more likely it > means writing no code at all, and just looking at STDERR of your live > usage. Works really well for >95% of Python scripts. > > The most important thing to consider is: What happens if my code > doesn't run all the way through? Is it safe for this to run part way, > then bomb with an exception? For many scripts, it's pretty easy: fix > the problem and rerun the script, and it'll completely rewrite its > output file. For others, this is a good reason for putting all your > "real data" into a transactional database - you begin a transaction at > the top, don't commit till the end, and if an exception kills your > script, your transaction will be rolled back. I have a system for > patching our database based on a script (written in Pike, not Python, > but the same applies); if I have any sort of critical failure in the > patch script, it'll bomb out as soon as I test it - but since I use > PostgreSQL, all that DDL (eg "ALTER TABLE") is covered by > transactional integrity (which it isn't with MySQL - another reason to > be wary of MySQL), so my patch will be backed out, and I can fix it > and start over. I don't need to have a Look Before You Leap approach > to database changes - I can simply do stuff, and if it crashes, all's > well. (That same script also has a system for catching errors at a > mid-level point that means that the process doesn't terminate when > there's an error; it supports full code reload, so once I fix the > patch, I send the process a SIGHUP and it fetches from disk again.) > *That* is error handling the safe way. > Oh, I get it! Thanks.