Python + VTE + readline = Xlib errors
Jeff Binder
extruded at gmail.com
Fri Sep 24 15:13:41 PDT 2010
Hello,
I'm trying to write a Python/GTK program that uses the forkpty()
function of VTE. The code works fine on my Ubuntu jaunty system, but
I'm having trouble getting it to work on the Mac (using the MacPorts
distribution of Python 2.6 on Snow Leopard), and I suspect it might be
a bug. It works fine until I try to use readline inside the PTY -
then I get Xlib errors.
Sometimes this shows up in the VTE terminal:
Assertion failed: (XLIB_SEQUENCE_COMPARE(event_sequence, <=,
dpy->request)), function poll_for_event, file xcb_io.c, line 221.
And sometimes I get this in the terminal from which I ran the program:
** Message: pygobject_register_sinkfunc is deprecated (GtkWindow)
** Message: pygobject_register_sinkfunc is deprecated (GtkInvisible)
** Message: pygobject_register_sinkfunc is deprecated (GtkObject)
Xlib: extension "RANDR" missing on display "/tmp/launch-d0DaeS/org.x:0".
The program 'main.py' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadIDChoice (invalid resource ID chosen for this connection)'.
(Details: serial 180 error_code 14 request_code 1 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
Below is a simple program that exhibits the problem. I apologize if
this is actually my fault and not a MacPorts problem, but I'm not sure
where else to go.
Jeff
---
import gtk
import os
import readline
import signal
import sys
import vte
window = gtk.Window()
term = vte.Terminal()
term_pid = term.forkpty()
if term_pid == -1:
raise EnvironmentError('Unable to create PTY process!')
if term_pid == 0:
while 1:
line = raw_input('>>>') # BOOM!
# But if I substitute:
# sys.stdout.write('>>>'); line = sys.stdin.readline()[:-1]
# everything works fine.
print line
def msg_delete(*args, **kwargs):
os.kill(term_pid, signal.SIGKILL)
gtk.main_quit()
window.connect('delete-event', msg_delete)
window.add(term)
window.show_all()
gtk.main()
More information about the macports-users
mailing list