Re: About libvirt.py stdout redirection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 16, 2014 at 06:31:02PM +0800, me,apporc wrote:
> Dear developers,
> As we know libvirt.py using libvirtmod.so, eg:
> 
>     def defineXML(self, xml):
>         """Define a domain, but does not start it.
>         This definition is persistent, until explicitly undefined with
>         virDomainUndefine(). A previous definition for this domain would be
>         overriden if it already exists. """
>         ret = libvirtmod.virDomainDefineXML(self._o, xml)
>         if ret is None:raise libvirtError('virDomainDefineXML() failed',
> conn=self)
>         __tmp = virDomain(self,_obj=ret)
>         return __tmp
> 
> 
> In my python program
> 
> #test.py
> import libvirt
> conn=libvirt.open("qemu:///system")
> xml=...
> conn.defineXML(xml) # Because i need this xml to be wrong for feature
> testing here
>  # Error will happen here, and error message is printed to stderr.
> 
> The error message is annoying.
> I need to know how to hide the error message printing to stderr by
> libvirtmod.
> 
> After i add sys.stderr = open('xxx', 'w') before invoking
> conn.defineXML(xml),  the error message is still printed to the terminal.
> Which means, i can redirect stderr to anywhere else in my python program,
>  but it changes back to terminal when control flow go to libvirtmod.

Do this:

  def libvirt_ignore(ignore, err):
      pass
  libvirt.registerErrorHandler(f=libvirt_ignore, ctx=None)

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]