[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Function stopping a function
From:       Duncan Booth <duncan.booth () invalid ! invalid>
Date:       2007-11-23 8:45:14
Message-ID: Xns99F15908A34D5duncanbooth () 127 ! 0 ! 0 ! 1
[Download RAW message or body]

Sorin Schwimmer <sxn02@yahoo.com> wrote:

> For instance, lenghty_function() executes, when an
> external event triggers cancel(), which is supposed to
> abruptly stop lengthy_function(), reset some variables
> and exit immediately.
> 

def lenghty_function(some, arguments, abort=lambda: False):
   while not abort():
      do some part of the function


then you just pass in whatever abort function is appropriate: it can check 
some flag to see whether the function should continue, or it might just 
check the current time and return True if the function has been going too 
long.
Just make sure that the badly spelled function calls abort() often.
-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic