Closing old connection after fork (Python)

Jami Pekkanen jami.pekkanen at nokia.com
Wed Aug 22 03:07:46 PDT 2007


Hello,

I'm writing a daemon which forks worker processes on demand. New worker
creation is done in following way:

pid = os.fork()

if(pid == 0):
	# Create new bus for the child process
	childBus = dbus.SessionBus(True)
	childBus.request_name('new.name.for.child')
        # Creates an object that's exported on the bus
        # with given path
        WorkerClass(childBus, '/new/path/for/child')

The runner process now works OK, but the problem is that the new process
will still sometimes catch method calls for the "parent" service and
this of course messes up the worker process tracking in the main
service.

So the old stuff should be cleaned up from the fresh process somehow so
it wont act as its parent. I've tried several methods, but nothing
really works.

Closing the old bus causes the newly requested name to disappear.
Removing all the match strings (childBus.remove_match_string('');
oldBus.remove_match_string()) doesn't work. Removing the object from the
new bus (serviceObject.remove_from_connection(childBus)) causes the main
service to disappear from all processes/connections.

So is there a method of starting a "fresh" D-Bus service in forked
thread at all?

- Jami Pekkanen



More information about the dbus mailing list