def send_notification(xn, ids, msg): try: rc = xn.notifications.send(to_ids=ids, notification=msg) except XiaoneiError,e: logging.error('Failed to call notifications.send') logging.error(e) if e.code == '10600': logging.debug('notification limit reached, trying to use other session key') session = SessionInfo.get_avail_session() if session: logging.debug(u'got available session: %s' % session) xn = create_xn_instance(session_key=session.session_key, uid=session.uid) try: rc = xn.notifications.send(to_ids=ids, notification=msg) except XiaoneiError,e: logging.error('Failed to call notifications.send with other session') logging.error(e) if e.code == '10600': logging.debug('this session has expired too. removing from db...') session.delete() except: