[gst-devel] GStreamer in double loop

Jeffrey Barish jeff_barish at earthlink.net
Fri Jun 19 00:48:39 CEST 2009

Arnout Vandecappelle wrote:

> On Thursday 18 June 2009 21:53:29 Jeffrey Barish wrote:
>> > You can use GLib's GIOChannel API to register the socket file
>> > descriptor, and get the GObject mainloop to poll it for you
>> > efficiently.
>> >
>> > See g_io_channel_unix_new () and g_io_add_watch ()
>> Normally a good approach.  One detail I omitted was that the sockets can
>> change, so in this case I don't see how I can use this approach.
>  When you create a new socket, you can also create a new IO channel and
>  watch
> for it, no?
>  If you want to change the sockets you are watching, you can remove the IO
> watch source and add it again later on.

Good question.  I don't create the new socket.  There's a server that tells
me what sockets it's using.  If it changes a socket, I'm listening to the
wrong one with g_io_add_watch, so I never find out that the server changed
it.  Mind you, the code that deals with these sockets is working in its own
thread.  If I can just get GObject to run in its own thread I'm done.

Here's what's baffling me.  This works:

        loop = gobject.MainLoop()
        context = loop.get_context()
        while True:

This doesn't:

        loop = gobject.MainLoop()
        context = loop.get_context()
        while True:

The difference is that the second one blocks on the iteration.  What is it
about blocking that is incompatible with running this code in its own
thread?  I found this statement in the documentation for Mainloop.run:

The run() method runs a mainloop until the quit() method is called. If this
is called for the thread of the loop's gobject.MainContext, it will process
events from the loop, otherwise it will simply wait.

I think that run is called from the thread of the loop's MainContext because
I just created the MainLoop on the previous line (imagine that lines 2-4
above are replaced by loop.run(), which should be equivalent).  However, I
am observing that run "simply wait[s]".  Could there be something in this
Jeffrey Barish

More information about the gstreamer-devel mailing list