I'm trying to write an example serial console implementation in python (attached), but I'm having some trouble getting stream events to do what I want. The console itself works fine as long as the domain stays up, but as soon as the domain shuts down the python script goes into a tight loop repeatedly calling the stream event callback. Debugging indicates that the stream event callback is being requested to be removed, but it never actually is removed which makes me think I am not properly releasing some resource, but I was under the impression that an error on a stream resulting in the stream aborting was supposed to free all the resources for me. Is that not correct? Thanks for any help anybody can provide, Dave
#!/usr/bin/python -u import sys, os, libvirt, tty, termios, atexit def reset_term(): termios.tcsetattr(0, termios.TCSADRAIN, attrs) def stdin_callback(watch, fd, events, unused): global run_console readbuf = os.read(fd, 1024) if readbuf.startswith(""): run_console = False return stream.send(readbuf) def stream_callback(stream, events, unused): if events & libvirt.VIR_EVENT_HANDLE_READABLE: receivedData = stream.recv(1024) os.write(0, receivedData) libvirt.virEventRegisterDefaultImpl() atexit.register(reset_term) attrs = termios.tcgetattr(0) tty.setraw(0) connection = libvirt.open(sys.argv[1]) domain = connection.lookupByUUIDString(sys.argv[2]) stream = connection.newStream(libvirt.VIR_STREAM_NONBLOCK) domain.openConsole(None, stream, 0) run_console = True stdin_watch = libvirt.virEventAddHandle(0, libvirt.VIR_EVENT_HANDLE_READABLE, stdin_callback, None) stream.eventAddCallback(libvirt.VIR_STREAM_EVENT_READABLE, stream_callback, None) while run_console: libvirt.virEventRunDefaultImpl()
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list