[PATCH] Add support for Python-based main loops
Submitted by Pavel Strashkin
Assigned to Simon McVittie
Description
Created attachment 60976 patch that adds support for python-based main loops
At the moment there is only native main loops that have to be written as Python/C extension so it's a big deal to integrate dbus and twisted as an example.
That patch fixes that situation plus provides 2 base main loops based on select(2) and poll(2). Each new main loop has to be inherited from dbus.mainloop.python.base.MainLoop and implement add_watch/remove_watch/add_timeout/remove_timeout/start/stop APIs.
If you need something more than I/O watchers and timers, you should take a look at gobject, libev, twisted or whatever else, and keep dbus's mainloop as simple as it possible. Just write a wrapper like GObjectMainLoop for dbus and continue using gobject as a primary instead of that main loop.
The usage of python-based main loop is simple. You have to import and install the main loop before any dbus call if you want that main loop to be the default.
from dbus.mainloop.python.select import SelectMainLoop mainloop = SelectMainLoop.install()
mainloop.start()
If you want to use the main loop only for certain connection or server (i don't see why), you still can do it.
import dbus from dbus.mainloop import PythonMainLoop from dbus.mainloop.python.select import SelectMainLoop
mainloop = SelectMainLoop() wrapper = PythonMainLoop(mainloop)
bus = dbus.SystemBus(mainloop=wrapper)
Attachment 60976, "patch that adds support for python-based main loops":
python-mainloop-support.patch