Python asyncore & dbus
Asked Answered
S

3

6

Is it possible to integrate asyncore with dbus through the same main loop?

Usually, DBus integration is done through glib main loop: is it possible to have either asyncore integrate this main loop or have dbus use asyncore's ?

Stalker answered 27/1, 2010 at 18:27 Comment(1)
Why would you use asyncore when you have glib? glib seems much more capable...Lashawnda
L
7

asyncore sucks. glib already provides async stuff, so just use glib's mainloop to do everything.

Lancastrian answered 27/1, 2010 at 18:32 Comment(0)
L
1

I wrote a trivial GSource wrapper for one of my own projects called AsyncoreGSource

Just attach it to an appropriate MainContext:

source = AsyncoreGSource([socket_map])
source.attach([main_context])

Naturally the defaults are asyncore.socket_map and the default MainContext respectively.

You can also try monkey-patching asyncore.socket_map, which would have been my solution had I not poked through the GLib python bindings source code for GSource.

Leisurely answered 14/1, 2011 at 9:29 Comment(1)
Note that I've since run into a few performance issues with this, and have a version that full integrates with GLib's poll interface on Linux (but not Windows). I'll update this answer when things stabilize.Leisurely
S
0

Although you got what is probably a perfectly reasonable answer, there is another approach - you don't need to use asyncore's loop per se. Just call asyncore.loop with a zero timeout and a count of 1, which stops it iterating (and thus makes the function name completely misleading) and polls the sockets just once. Call this as often as you need.

I don't know anything about glib's async support but if it requires threads you might still get better performance by using asyncore in this way since it will use select or poll and won't need to spawn additional threads.

Scherle answered 28/1, 2010 at 12:2 Comment(1)
thanks for your thoughts - I have settled on Twisted for this project.Stalker

© 2022 - 2024 — McMap. All rights reserved.