def cls_init(cls, check_options=True): if check_options: cls._check_view_options() # because of BaseView.cls_init is a bound method (@classmethod) # so we can only route BaseView._interface, not cls._interface defined by user BaseView.cls_init.__func__(cls) # super().cls_init() # fixed in 3.6 cls_full_name = get_class_full_name(cls) assert isinstance(cls.LIST_PAGE_SIZE, int), '%s.LIST_PAGE_SIZE must be int' % cls_full_name assert cls.LIST_PAGE_SIZE == -1 or cls.LIST_PAGE_SIZE > 0, \ '%s.LIST_PAGE_SIZE must be -1 or more than 0' % cls_full_name assert cls.LIST_PAGE_SIZE_CLIENT_LIMIT is None or isinstance(cls.LIST_PAGE_SIZE_CLIENT_LIMIT, int), \ '%s.LIST_PAGE_SIZE_CLIENT_LIMIT must be None or int' % cls_full_name if isinstance(cls.LIST_PAGE_SIZE_CLIENT_LIMIT, int): assert cls.LIST_PAGE_SIZE_CLIENT_LIMIT == -1 or cls.LIST_PAGE_SIZE_CLIENT_LIMIT > 0, \ '%s.LIST_PAGE_SIZE must be None or -1 or more than 0' % cls_full_name async def func(): await cls._fetch_fields(cls) if not cls._is_skip_check(): assert cls.table_name assert cls.data_model # assert cls.fields # assert cls.primary_key # assert cls.foreign_keys get_ioloop().run_until_complete(func())
def timer(interval_seconds, *, exit_when): """ Set up a timer :param interval_seconds: :param exit_when: :return: """ loop = get_ioloop() def wrapper(func): @functools.wraps(func) def runner(): if exit_when and exit_when(): return loop.call_later(interval_seconds, runner) if asyncio.iscoroutinefunction(func): asyncio.ensure_future(func()) else: func() loop.call_later(interval_seconds, runner) _decorator_fix(runner, func) return func return wrapper
def app_init(): import_path('api', base_path=os.path.abspath( os.path.join(os.path.dirname(__file__), '..'))) loop = get_ioloop() # loop.run_until_complete(redis.init(loop)) app._prepare()
async def on_startup(): loop = get_ioloop() if config.EMAIL_ENABLE: asyncio.ensure_future(mail.init(loop), loop=loop) await redis_init(loop) if config.UPLOAD_ENABLE: qn.init()
async def on_startup(): loop = get_ioloop() if config.EMAIL_ENABLE: asyncio.ensure_future(mail.init(loop), loop=loop) await redis_init(loop) if config.UPLOAD_ENABLE: if config.UPLOAD_BACKEND == 'qiniu': from lib import qn qn.init()
def run_in_thread(fn, *args, **kwargs): return futures.wrap_future( thread_executor.submit(fn, *args, **kwargs), loop=get_ioloop() )
def event_loop(): loop = get_ioloop() yield loop
import misc.setup import asyncio from app import app from lib import mail, qn from model.redis import init as redis_init from slim.utils import get_ioloop import config if __name__ == '__main__': import model._models import view._views loop = get_ioloop() if config.EMAIL_ENABLE: asyncio.ensure_future(mail.init(loop), loop=loop) co_redis = redis_init(loop) loop.run_until_complete(co_redis) if config.UPLOAD_ENABLE: qn.init() app.run(host=config.HOST, port=config.PORT)