def run():
    from utils.RedisHelper import RedisHelper
    _redis = RedisHelper()
    _redis.pubsub = _redis.conn.pubsub()
    _redis.pubsub.subscribe(_redis.sub_name)
    sub_message = next(_redis.pubsub.listen())
    print(sub_message)
    for message in _redis.pubsub.listen():
        if (('message' != message['type']) or (_redis.sub_name != sub_message['channel'].decode('utf-8', 'ignore'))):
            print('type erro')
            continue
        message['data'] = message['data'].decode('utf-8', 'ignore')
        try:
            data = json.loads(message['data'])
        except:
            print('json parse error', message)
            continue
        if ('type' not in data):
            continue
        if ('initialize' != data['type']):
            continue
        if ('uid_list' not in data['data']):
            continue
        id_list = data['data']['uid_list']
        try:
            uid = _redis.conn.rpop(id_list).decode('utf-8', 'ignore')
        except:
            print('uid error', uid)
            continue
        if (int(uid) >= data['data']['sub_count']):
            raise 'uid Index exceeded'
        if find_spec(('handlers.' + data.get('type', '')), package='..'):
            handlers = importlib.import_module(('handlers.' + data.get('type', '')), package='..')
        else:
            continue
            raise 'import error'
        p = Process(target=handlers.run, args=[data, int(uid)])
        p.start()
        p.join()
def run():
    from utils.RedisHelper import RedisHelper
    _redis = RedisHelper()
    _redis.pubsub = _redis.conn.pubsub()
    _redis.pubsub.subscribe(_redis.sub_name)
    sub_message = next(_redis.pubsub.listen())
    print(sub_message)
    for message in _redis.pubsub.listen():
        if (('message' != message['type']) or (_redis.sub_name != sub_message['channel'].decode('utf-8', 'ignore'))):
            print('type erro')
            continue
        message['data'] = message['data'].decode('utf-8', 'ignore')
        try:
            data = json.loads(message['data'])
        except:
            print('json parse error', message)
            continue
        if ('type' not in data):
            continue
        if ('initialize' != data['type']):
            continue
        if ('uid_list' not in data['data']):
            continue
        id_list = data['data']['uid_list']
        try:
            uid = _redis.conn.rpop(id_list).decode('utf-8', 'ignore')
        except:
            print('uid error', uid)
            continue
        if (int(uid) >= data['data']['sub_count']):
            raise 'uid Index exceeded'
        if find_spec(('handlers.' + data.get('type', )), package='..'):
            handlers = importlib.import_module(('handlers.' + data.get('type', )), package='..')
        else:
            continue
            raise 'import error'
        p = Process(target=handlers.run, args=[data, int(uid)])
        p.start()
        p.join()