Blocking ctrl-c to os.popen() or os.system()

pythonhda pythonhda at yahoo.com.replacepythonwithlinux
Sat Jan 4 21:38:12 EST 2003


Maybe you can try to catch the exception?

while doing_something:
	try:
		.....
	except KeyboardInterrupt:
		print "I'm not done yet"



On 4 Jan 2003 14:00:35 -0800
sandeep182 at hotmail.com (Sandeep Gupta) wrote:

> I am executing a command from python via os.popen().  While the
> command is executing, if I type ctrl-c, the command receives the
> interrupt.  I would like to block the ctrl-c from the command and I've
> tried the following:
> 
> 1)Using python's signal module to ignore SIGINT.  This causes python
> to ignore SIGINT, but a ctrl-c that is typed during the popen() call
> still goes to the command.
> 
> 2)Adding "< /dev/null" to the os.popen() call.  This doesn't help.
> 
> 3)Using popen2() and immediately closing the stdin file.  This also
> doesn't work.
> 
> Any suggestions would be greatly appreciated!
> 
> Thanks
> Sandeep




More information about the Python-list mailing list