473,408 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Sending C-c to Emacs

Hi all,

I've written a Python script with functionality similar to the Unix
"script" program, which keeps a record of shell commands issued (I
capture some additional stuff like timestamps). The code is borrowed
largely from
http://groups.google.com/group/comp....40b36c6f0c53cc

Anyways, one problem is that it doesn't handle Control-C correctly.
This is a particular problem when invoking Emacs since C-x C-c is the
sequence to exit Emacs. Catching the KeyboardInterrupt and doing
os.kill(pid,signal.SIGINT) doesn't seem to do the trick.

A simplified version of the program looks something like this (I've
eliminated the parts where I log the data to a file and some
tty-related cleanup stuff, this is just shuffling data between user
and shell)

import select,os,pty
shell = '/bin/bash'
pid, fd = pty.fork()
if pid == 0:
os.execvp(shell,(shell,))

# various tty magic goes here

exit = 0
while True:
r, w, e = select.select([0, fd], [], [], 1)
for File in r:
if File == 0:
from_user = os.read(0, bufsize)
os.write(fd, from_user)
elif File==fd:
try:
from_shell = os.read(fd, bufsize)
os.write(1, from_shell)
if from_shell=='':
exit=1
except OSError:
exit=1
if exit==1:
break
The problem is that this doesn't work when the user hits Control-C. I
thought the solution would be to send the child process a SIGINT, and I
tried to do that as follows:

try:
r, w, e = select.select([0, fd], [], [], 1)
...
except KeyboardInterrupt:
os.kill(pid,signal.SIGINT)
But that doesn't have the desired effect. When I have this code here,
it's as if I never hit Control-C at all. What's the proper way to pass
the Control-C to the child process?

Thanks,

Lorin Hochstein

Apr 4 '06 #1
1 1638
I figured out the problem, fix involves modifying one of the lines in
the original program (from
http://groups.google.com/group/comp....40b36c6f0c53cc)
to:
raw_lflag = self.lflag & ~(termios.ICANON|termios.ECHO|termios.ISIG)

(termios.ISIG was added)
Lorin

Apr 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Christian Seberino | last post by:
I am looking at the ELSE home page and trying to figure out if I should invest the time to learn about the ELSE minor mode for Emacs. Is there any programmer out there using ELSE that is getting...
5
by: Tuxtrax | last post by:
Hi all My editor of choice on linux for python, bar none, is xemacs. I love the python mode that detects a python file and handles indentation and coloration for me automagically. I have been...
49
IDE
by: Thomas Lindgaard | last post by:
Hello I am probably going to start a war now... but so be it :) I just want to hear what all you guys who eat pythons for breakfast use for python coding. Currently I use Kate, but I would...
81
by: julio | last post by:
Sorry but there is no another way, c# .net and mono are going to rip python, not because python is a bad lenguage, but because is to darn old and it refuses to innovate things, to fix wrong things,...
12
by: Thomas Bartkus | last post by:
Does anyone use emacs together with both WordStar key bindings and python mode? I'm afraid that Wordstar editing key commands are burned R/O into my knuckles! I would like to play with emacs...
7
by: Xah Lee | last post by:
Summary: when encountering ex as a unit in css, FireFox (and iCab) did not take into account the font-family. Detail: http://xahlee.org/js/ff_pre_ex.html Xah xah@xahlee.org ∑...
4
by: emin.shopper | last post by:
Emacs seems to freeze when doing certain shell commands on Microsoft Windows. The following is a simple example with Xemacs: ---------------------------------------------------------- ...
5
by: levander | last post by:
I've been using pdb under emacs on an Ubuntu box to debug python programs. I just upgraded from Ubuntu Edgy to Feisty and this combo has stopped working. Python is at 2.5.1 now, and emacs is at...
331
by: Xah Lee | last post by:
http://xahlee.org/emacs/modernization.html ] The Modernization of Emacs ---------------------------------------- THE PROBLEM Emacs is a great editor. It is perhaps the most powerful and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.