Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Decorators not worth the effort

Received: by 10.180.106.199 with SMTP id gw7mr442590wib.0.1348233585146;
        Fri, 21 Sep 2012 06:19:45 -0700 (PDT)
Path: q11ni9084552wiw.1!nntp.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!94.232.116.12.MISMATCH!feed.xsnews.nl!border-2.ams.xsnews.nl!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.news.ucla.edu!nntp.club.cc.cmu.edu!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: Duncan Booth <duncan.bo...@invalid.invalid>
Newsgroups: comp.lang.python
Subject: Re: Decorators not worth the effort
Date: 14 Sep 2012 11:26:10 GMT
Lines: 39
Message-ID: <XnsA0CE7D6F43F18duncanbooth@127.0.0.1>
References: <mailman.690.1347614888.27098.python-list@python.org>
Reply-To: duncan.bo...@suttoncourtenay.org.uk
Mime-Version: 1.0
X-Trace: individual.net j2tLf03GKHLBUkI1RawBFgiqbo21zrg4zER+sN4M7+8HKG5Z1Gw5IAcQ+RJalcm4S9
Cancel-Lock: sha1:qkSmIqCuz1xNP7dXdYp9coXYp8U=
User-Agent: Xnews/2006.08.24 Hamster/2.1.0.11
X-Face: .C;/v...@2k.C(.1v-}d=`|7AQ-%,#A$0ZGtAkLPvuawAM>3#D,pXaAb31%(=Gn2ZZK/Z~fd0y4't5iKK~F":}F2*|\mQYX+BUr4ZM*|+`@o-TKzFGwsJnan{)*b~QJ-Fu^u'$$nYV
Bytes: 2498
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Jean-Michel Pichavant <jeanmic...@sequans.com> wrote:

> I wrote the following one, used to decorate any function that access
> an equipment, it raises an exception when the timeout expires. The
> timeout is adapted to the platform, ASIC of FPGA so people don't need
> to specify everytime one timeout per platform. 
> 
> In the end it would replace 
> 
> def boot(self, timeout=15):
>     if FPGA:
>         self.sendCmd("bootMe", timeout=timeout*3)
>     else:
>         self.sendCmd("bootMe", timeout=timeout)
> 
> with
> 
> @timeout(15)
> def boot(self, timeout=None):
>     self.sendCmd("bootMe", timeout)
> 
> I wrote a nice documentation with sphinx to explain this, how to use
> it, how it can improve code. After spending hours on the decorator +
> doc, feedback from my colleagues : What the F... !! 
> 

I'd agree with your colleagues. How are you going to ensure that all 
relevant functions are decorated and yet no decorated function ever 
calls another decorated one?

From the code you posted it would seem appropriate that the adjustment 
of the timeout parameter happen in the `sendCmd()` method itself and 
nowhere else. Alternatively use named values for different categories of 
timeouts and adjust them on startup so instead of a default of `timeout=
15` you would have a default `timeout=MEDIUM_TIMEOUT` or whatever name 
is appropriate.

-- 
Duncan Booth http://kupuguy.blogspot.com