def fake_async_decorator(ocls):
"""
Wrap all non-private methods of a class with the tornado Task decorator.
Used to simulate the interface of async methods, but with methods that actually block.
TODO: Test.
"""
import tornado
import tornado.gen
cls = type(ocls.__name__ + 'Async', ocls.__bases__, dict(ocls.__dict__))
for attr in cls.__dict__:
if callable(getattr(cls, attr)) and (not attr.startswith('_')):
def fake(*args, **kw):
yield tornado.gen.Task(getattr(cls, attr)(*args, **kw))
setattr(cls, attr, fake)
return cls
评论列表
文章目录