Closing old connection after fork (Python)
Havoc Pennington
hp at redhat.com
Wed Aug 22 06:19:25 PDT 2007
Hi,
It isn't 100% clear to me how you're doing this and what's breaking,
but in general
the DBusConnection in the end is a socket file descriptor. I *think* it has the
close-on-exec flag set, so if your child exec'd it should be closed.
If you just fork
though, then both parent and child would have a copy; and I don't think anything
sane can possibly happen in that context, since two processes will be
trying to read and write from the same connection socket.
Maybe it's as simple as in the child, be sure to create a *private*
bus object with dbus_bus_get_private(), which means you'll open a new
descriptor instead of potentially re-using the parent one (or is this
already what the True in SessionBus(True) does in python?)
But you'd still have to be very careful not to touch the shared
connection from the parent, if any, and disable any main loop setup on
the child's copy of the shared connection.
I don't know about this whole line of development though... fork()
without exec() is pretty tricky, you are very likely to be better off
with threads or some other architecture.
Havoc
More information about the dbus
mailing list