Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!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.042 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'exception.': 0.07; 'throw': 0.09; 'def': 0.14; 'command,': 0.16; 'shell': 0.18; 'terminate': 0.22; 'code,': 0.23; 'header:In-Reply-To:1': 0.24; 'executing': 0.27; 'url:moin': 0.27; 'message-id:@mail.gmail.com': 0.28; 'url:wiki': 0.30; 'to:name:python-list': 0.31; "i'd": 0.31; 'seconds': 0.31; 'skip:d 20': 0.32; 'url:python': 0.33; 'received:google.com': 0.34; 'to:addr:python-list': 0.35; 'generic': 0.35; 'url:org': 0.36; 'subject:: ': 0.37; 'skip:g 20': 0.37; 'does': 0.39; 'to:addr:python.org': 0.39; 'some': 0.40; 'within': 0.64; 'answer:': 0.84 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 :content-type; bh=hWw+KEAh4kbxKwOqwFBZjoFIUJckMpWHb9CQ7q0xwkA=; b=FAHaaQFckws+yEsIAwsgC1FDAWj9fie1TSYUTnC9/A0MU4NpQ8CbertS2L+ysj1sux gepW461qhx+v7vql4f/ZF1OeHIrDuQ91oIODWT2/tNnMXForBRTnE0S6bxrjo+4AYjrk Cc0iwReGYJ7x2dF39CM5rTrG7cfAVRS2+OAmcgQ7qmuO7B9hYIrs6kVyK5lrTx8SJCrB FoUZwqXx7g6Ac07iZqNzbmth6qDwlYnOLQAUJhwGKtsBu1P4vILjl2RlmROwI+nSFgfk x48tGKVOnDyE0XDEDOn1uPyM9UoTAcQ5BtQJrIfuK10y/YbhoPW+RSdk5ykD5sk9UM10 srQw== MIME-Version: 1.0 X-Received: by 10.194.60.43 with SMTP id e11mr20845565wjr.36.1432351238141; Fri, 22 May 2015 20:20:38 -0700 (PDT) In-Reply-To: References: Date: Fri, 22 May 2015 21:20:38 -0600 Subject: Re: decorators and alarms From: Jason Friedman To: python-list Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432351246 news.xs4all.nl 2822 [2001:888:2000:d::a6]:41857 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3351 X-Received-Body-CRC: 2253602893 Xref: csiph.com comp.lang.python:91088 > But, I'd like to expand this to take some generic code, not just a > shell command, and terminate it if it does not return quickly. > > @time_limiter > def generic_function(arg1, arg2, time_limit=10): > do_some_stuff() > do_some_other_stuff() > return val1, val2 > > If generic_function does not finish within 10 seconds it would stop > executing and throw an exception. Found an answer: https://wiki.python.org/moin/PythonDecoratorLibrary#Function_Timeout