Function stopping a function
hdante at gmail.com
hdante at gmail.com
Fri Nov 23 10:07:49 EST 2007
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... at yahoo.com> wrote:
> 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
>
More information about the Python-list
mailing list