async def get(self): logger.info('get DemoHandle') s = await get_session(self.request) if 'skey' in s: logger.info('session work ok') else: s['skey'] = '123' return web.Response(text="New hope")
def load_keywords_for_all(coll, all_cnt): logger.debug('load_keywords') try: k_cn = load_chinese_keyword(all_cnt) logger.debug('load chinese keywords: {}'.format(k_cn)) k_en = load_english_keyword(all_cnt) logger.debug('load english keywords: {}'.format(k_en)) keywords = [] + k_cn + k_en coll.update({'types': 'keyword'}, { '$set': { 'types': 'keyword', 'keywords': keywords, 'modified_at_gmt': utcnow() } }, upsert=True) except Exception as err: logger.exception(err) else: logger.info('keyword done.')
def callback(*args, **kw): logger.info('tasks heart!') gc.collect() ioloop.call_later(60, callback, *args, **kw)
def bind_handle(add_route): logger.info('bind_handle') add_route('/', DemoHandle)
def bind_task(): logger.info("run web_demo")
async def load_img_labels(aws_conn, im): logger.info('detect image...') return await ioloop.run_in_executor(thread_executor, _load_img_labels, aws_conn, im)
def _load_img_labels(aws_conn, im): logger.info('request to deteck image...') return aws_conn.detect_labels(Image={'Bytes': im.read()}, MaxLabels=10)
async def download_img(url): logger.info('download image {}'.format(url)) with aiohttp.ClientSession() as session: async with session.get(url) as resp: return BytesIO(await resp.read())
def bind_handle(add_route): logger.info('bind_handle aws.rekognition') add_route('/detect/', DemoHandle)
def callback(): later = 60 * 60 * 12 # 12 hr logger.debug('add new task load_keywords after {}'.format(later)) logger.info('Run task load_keywords') process_executor.submit(load_and_save_post_cnt_and_keywords) ioloop.call_later(later, callback)
async def get(self): logger.info('get WebApps') return None
def bind_handle(add_route): logger.info('bind_handle') add_route('/', WebApps)
def bind_task(): logger.info("run webapps")