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

List:       python-list
Subject:    Re: Function stopping a function
From:       "hdante () gmail ! com" <hdante () gmail ! com>
Date:       2007-11-23 15:07:49
Message-ID: 622401ec-3db7-4dc3-bf5e-e47cb98593d9 () w40g2000hsb ! googlegroups ! com
[Download RAW message or body]


 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.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
>
-- 
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