Beispiel #1
0
        ret = {
            'status': '100',
            'message': 'OK',
            'data': res
        }
        if isinstance(ret, dict):
            ret = json.dumps(ret)
        tornado.ioloop.IOLoop.instance().add_callback(lambda: hnd.finish(ret))
    except BizError, e:
        ret = {
            'status': e.code,
            'message': e.reason,
        }
        tornado.ioloop.IOLoop.instance().add_callback(lambda: hnd.finish(json.dumps(ret)))
    except Exception, e:
        logger.exception(e)
        tornado.ioloop.IOLoop.instance().add_callback(lambda: hnd.send_error(500))


class ThreadBaseMeta(type):
    @classmethod
    def _meta_call(cls, func):
        fun = tornado.web.asynchronous(func)
        return fun

    def __new__(mcs, name, fathers, attrs):
        # print mcs
        for name, value in attrs.iteritems():
            if name in ['get', 'post', 'delete', 'head', 'put', 'options', 'patch'] and type(value) == FunctionType:
                value = mcs._meta_call(value)
                attrs[name] = value