python程序里需要在一个线程里运行 pyppeteer 结果报了下边这个一场信息【ValueError: signal only works in main thread】

参考:https://blog.csdn.net/weixin_41822224/article/details/103719863

必须增加在多线程中才能运行

"handleSIGINT": False,
            "handleSIGTERM": False,
            "handleSIGHUP": False

import asyncio
from pyppeteer import launch
import time
from app.libs.thread.own_thread import OwnThread

is_mobile_browser = False

_defaultViewport = {
    "width": 375,
    "height": 668,
    "isMobile": True,
    "hasTouch": True,
} if is_mobile_browser else {
    "width": 998,
    "height": 800,
    "isMobile": False,
    "hasTouch": False,
}


async def temp_func():
    browser = await launch(
        options={
            'headless': False,
            'args': ['--no-sandbox'],
            "defaultViewport": _defaultViewport,
            "handleSIGINT": False,
            "handleSIGTERM": False,
            "handleSIGHUP": False
        })
    page = await browser.newPage()
    await page.setJavaScriptEnabled(enabled=True)
    await page.goto('www.baidu.com')

    ele = await page.J(".main")

    print(await (await ele.getProperty("src")).jsonValue())
    time.sleep(30)
    await browser.close()


OwnThread(lambda: asyncio.run(temp_func())).start()

print("aaaa")

 

@app.route('/get_trip_time', methods=['POST']) def get_trip_time(): data = request.get_json() method = data['method'] center_coor = data['center_coor'] t = data['t'] radius = get_radius(method, t) gtt = GetTripTime(method, center_coor, t, radius) gtt.main() return jsonify({'message': 'Trip time data collected successfully'}) @app.route('/visualize_trip_time', methods=['GET']) def visualize_trip_time(): data = pd.read_csv('time1.csv') lng = data['lng'] lat = data['lat'] time = data['time'] grid_lng, grid_lat = np.meshgrid(np.linspace(lng.min(), lng.max(), 100), np.linspace(lat.min(), lat.max(), 100)) grid_time = griddata((lng, lat), time, (grid_lng, grid_lat), method='linear') fig, ax = plt.subplots(figsize=(8, 8)) contour_plot = ax.contourf(grid_lng, grid_lat, grid_time, cmap='jet', levels=6) ax.contour(contour_plot, colors='k', linewidths=0.5) plt.colorbar(contour_plot) last_lng = lng.iloc[-1] last_lat = lat.iloc[-1] ax.scatter(last_lng, last_lat, color='green', marker='o', s=50, label='Start Point') ax.legend() plt.title('Isochrone') ax.set_xlabel('Longitude') ax.set_ylabel('Latitude') ax.xaxis.set_major_formatter(mticker.FormatStrFormatter('%.2f')) plt.show() return jsonify({'message': 'Trip time visualization generated successfully'}) @app.route('/get_isochrone_coords', methods=['GET']) def get_isochrone_coords(): with open('contour_coords.json', 'r') as f: contour_coords = json.load(f) return jsonify(contour_coords)用rest client调用GET http://localhost:5000/visualize_trip_time时ValueError: signal only works in main thread of the main interpreter
07-25
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值