By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,550 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,550 IT Pros & Developers. It's quick & easy.

Function stopping a function

P: n/a
Hi All,

We all know that a function can launch the execution
of another function. How can a function stop the
execution of another function?

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.

Thanks for your advice
SxN
__________________________________________________ __________________________________
Be a better sports nut! Let your teams follow you
with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=...1G1SQtBI7ntAcJ
Nov 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Sorin Schwimmer <sx***@yahoo.comwrote:
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.
Nov 23 '07 #2

P: n/a

Note, this only works in Unix systems:

import os, signal

def long_process():
while True: print "I'm messing with your terminal ! ",

def short_process(long_process_id):
raw_input('Press [Enter] to kill the bad process')
os.kill(long_process_id, signal.SIGKILL)
print
print 'Hehe !'

def main():
print 'Starting two processes (press [Enter]): '
raw_input()
pid = os.fork()
if (pid != 0):
short_process(pid)
else:
long_process()

main()
On Nov 23, 2:30 am, Sorin Schwimmer <sx...@yahoo.comwrote:
Hi All,

We all know that a function can launch the execution
of another function. How can a function stop the
execution of another function?

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.

Thanks for your advice
SxN
Nov 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.