pty/fork and SIGINT

Donn Cave donn at drizzle.com
Tue Dec 18 05:40:44 CET 2001


Quoth bsturk at news.rcn.com (Brian Sturk):
| I'm using the pty module to to "control" a shell process
| and I'm having a hard time getting SIGINT to be sent to
| the processes spawned within it, i.e. ping <hostname>.
|
| I've tried registering a handler via signal.signal and externally
| sending it SIGINT with the pid returned from fork() using kill, 
| and also using the returned pid from fork() to send it a signal.SIGINT
| from within the script.  Nothing I've tried seems to work.
|
| The script is a little large to post here but it basically
| is run within the editor vim so there are a few variables at work.
| I'm wondering if the problem is that I'm never returning control 
| to the editor since I continually have data to be read().  I'm not
| a signal/process guru so I'm unsure where to look. 

Works for me.  I'm running BeOS right now, so that's where I tried it,
but I imagine it will work under UNIX too.

You have a big problem there - as you recognize, with a big script and
an unusual operating environment and all, it's hard to say where it's
going wrong.  You need to simplify.  You can run ping behind a pty and
print out the output in a few lines of code;  now use posix.kill to
deliver your signal to the ping process.  Works?  Hm.  Run a simple
sleep process from vim, let it die naturally.  That working?  Kill it,
still works like you expect?  Etc.

When you have a simple 20 line script that we can run and see the
same problem for ourselves, then you can hope for help.  (But I bet
you'll find the problem on your own in the process.)

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list