'Detects and returns an existing D-Bus session bus address.
:returns: string -- D-Bus session bus address. If a running D-Bus session was not detected, returns None.'

def _get_existing_dbus_session(self):

    uid = os.getuid()
    self.module.debug(('Trying    to    detect    existing    D-Bus    user    session    for    user:    %d' % uid))
    for pid in psutil.pids():
        process = psutil.Process(pid)
        (process_real_uid, _, _) = process.uids()
        try:
            if ((process_real_uid == uid) and ('DBUS_SESSION_BUS_ADDRESS' in process.environ())):
                dbus_session_bus_address_candidate = process.environ()['DBUS_SESSION_BUS_ADDRESS']
                self.module.debug(('Found    D-Bus    user    session    candidate    at    address:    %s' % dbus_session_bus_address_candidate))
                command = ['dbus-send', ('--address=%s' % dbus_session_bus_address_candidate), '--type=signal', '/', 'com.example.test']
                (rc, _, _) = self.module.run_command(command)
                if (rc == 0):
                    self.module.debug(('Verified    D-Bus    user    session    candidate    as    usable    at    address:    %s' % dbus_session_bus_address_candidate))
                    return dbus_session_bus_address_candidate
        except psutil.AccessDenied:
            pass
    self.module.debug('Failed    to    find    running    D-Bus    user    session,    will    use    dbus-run-session')
    return None
