Running GUI and "GObject.mainloop.run()" together?
Ajay Garg
ajaygargnsit at gmail.com
Tue Dec 25 05:58:23 PST 2012
Hi all.
I figured out a solution :)
By using the ".add_signal_receiver" python API, I can "ping" the child
process, even if it has just the "Gtk.main()" loop running (and not the
"GObject.mainloop" + "dbus.mainloop.glib.DBusGMainLoop" combination
running).
This way, the "server" (listening for the signal) is set.
Just one question, currently for the client, I am having the (client)
(parent) process run the command "dbus-send" via the python-subprocess API.
Does there exist a python API to do it in a cleaner manner?
On Tue, Dec 25, 2012 at 1:12 PM, Ajay Garg <ajaygargnsit at gmail.com> wrote:
> I would like to elaborate more on my more findings of case b) and c); I
> hope to be as thorough as possible ::
>
>
>
> *
> I have almost confirmed from my side, that is impossible to run two loops
> in a single thread of execution.
>
> So, for example, once the GUI sets in via
> Gtk.main()
>
> that's it.. the thread will now not proceed to any further of code.
>
>
> Same happens, if the other loop, is run via ::
>
> dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
> session_bus = dbus.SessionBus()
> name =
> dbus.service.BusName("org.example.Sample", session_bus)
> object = ExampleObject(session_bus,
> '/ExampleObject')
> mainloop = GObject.MainLoop()
>
> So, if two different loops need to be run, we need to have threads. Period.
>
> PLEASE LET ME KNOW IF MY ASSERTIONS ARE CORRECT :)
>
>
>
> *
> Now, when I tried running the two loops in two different threads, I
> enountered strange errors.
> I dare say that they seem to be due to inappropriate specification of the
> event sources for the two loops (which in turn is wholly due to my limited
> knowledge of dbus-loops).
>
> Which brings me to the following related questions ::
>
> 1)
> As per
> http://www.pygtk.org/pygtk2reference/class-gobjectmainloop.html, it seems
> that we must be able to add event sources to
> gobject.mainloop; however, I do not see any way to that.
>
> HOW CAN EVENT SOURCES BE ADDED?
>
>
> 2)
> Once the event sources are added, each instance of
> gobject.mainloop (in its particular thread), will cater to only those
> sources.
>
> PLEASE LET ME KNOW IF MY ASSERTION IS CORRECT.
>
>
> 3)
> How is dbus."mainloop.glib.DBusGMainLoop(set_as_default=True)"
> related to gobject.mainloop?
>
>
> 4)
> How is
> dbus."mainloop.glib.DBusGMainLoop(set_as_default=False)" related to
> gobject.mainloop?
>
>
> 5)
> Is it necessary at all to specify
> "mainloop.glib.DBusGMainLoop(set_as_default=True)" or
> "mainloop.glib.DBusGMainLoop(set_as_default=False)" when using
> gobject.mainloop?
>
>
> I know some of the answers are obvious (like points 2 and 5), but I notice
> whatever I have searched on the net, people are just happy to get things
> working.
> This is ok if there is just a single thread with a single
> gobject.mainloop, but things get monstrous when two loops (one a
> "Gtk.main()", and other "gobject.mainloop") come in; as now things won't
> work unless there is a clear understanding of what each line of
> bootstrapping-code does.
>
>
> I will be grateful to receive any in-sights in this.
>
>
>
>
>
>
>
>
>
> On Mon, Dec 24, 2012 at 1:56 PM, Ajay Garg <ajaygargnsit at gmail.com> wrote:
>
>> Hi all.
>>
>> This is another question that arises as part of my efforts to run a GUI
>> application, as well as a dbus-service within the same process.
>> (The other question being at
>> http://mail.python.org/pipermail/python-dev/2012-December/123287.html)
>>
>> For a recap of the brief history, I have a parent process, that is
>> spawning a child process via "subprocess".
>> Currently, the child-process is a GUI process; however, I intend to
>> "behave" it as a dbus-service as well.
>>
>> Thus,
>>
>> a)
>> I subclassed the child-process "main" class with "dbus.service.Object";
>> however, I then got the error
>> "metaclass conflict: the metaclass of a derived class must be a (non-
>> strict) subclass of the metaclasses of all its bases"
>>
>>
>> b)
>> I then used composition, wherein another class, "RemoteListener"
>> deriving from "dbus.service.Object" was made an attribute of the "main"
>> class. That worked.
>> However, when I do
>>
>> dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
>> GObject.mainloop.run()
>>
>> in the "RemoteListener"'s __init__ method, the GUI of the "main" class
>> fails to load (apparently, because the "mainloop.run()" causes the
>> singular, main-thread to go into busy-wait).
>>
>>
>> c)
>> I tried option b), but now instantiating "RemoteListener" in a separate
>> thread; however, no improvement :(
>>
>>
>>
>>
>> Is there a way to run GUI and a dbus-service together? Or is a
>> dbus-service pure "backend" process? :P
>>
>> I will be grateful for any pointers; if you need me to test anything
>> else, please let me know, I will be more than willing :)
>>
>>
>>
>>
>> Regards,
>> Ajay
>>
>
>
>
> Regards,
> Ajay
>
Regards,
Ajay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20121225/7aa54151/attachment-0001.html>
More information about the dbus
mailing list