【发布时间】:2019-12-14 18:36:59
【问题描述】:
我有一个烧瓶应用程序,它接收请求并尝试从给定的 URL 截取屏幕截图,这是使用 asyncio 函数完成的。
我所做的是,
import asyncio
from pyppeteer import launch
from flask import Flask
import base64
from flask import Blueprint, jsonify, request
import jwt
async def main():
browser = await launch(headless=True)
page = await browser.newPage()
await page.goto(target)
await page.screenshot({'path': '/tmp/screen.png', 'fullPage': True})
await browser.close()
app = Flask(__name__)
@app.route('/heatMapDbConfigSave', methods=['POST'])
def notify():
token, target,id = map(
request.form.get, ('token', 'target','id'))
asyncio.get_event_loop().run_until_complete(main(target))
if __name__ == '__main__':
app.run(host='localhost', port=5002, debug=True)
我遇到的问题是,得到错误 RuntimeError: There is no current event loop in thread 'Thread-2'. 。我已经用谷歌搜索并浏览了以前的帖子。没有任何帮助,也没有指出明确的解决方案。
解决这个问题的方法是什么?
提前致谢!
【问题讨论】:
标签: python python-3.x flask python-multithreading