Open JimLee1996 opened 4 years ago
作者你好,项目非常实用,也写的非常好。
最近我在配合aiokafka+asyncio+service_streamer的时候遇到了问题,即调用streamer的时候发生了阻塞,streamer的输出日志中,导致每个task的batch为1。
我的疑惑如下:
问题的原因是不是因为streamer的实现是针对多线程(比如flask)或者多进程的,对于原生的python协程而言,会阻塞掉当前的loop。
有没有什么比较好的方法或者小trick可以解决这个问题
希望你帮忙看看并提些建议吧,谢谢~
async for msg in consumer: recv_time = int(time.time() * 1000) passId = msg.value['passId'] imgURL = msg.value['imgURL'] imgPath = msg.value['path'] # get image img = await fetcher.get_img(imgURL) # TODO async # backend process item = streamer.predict([img])[0] # post result send_time = int(time.time() * 1000) result = create_result(passId, recv_time, send_time, imgPath, item) await poster.post_result(result)
用asyncio的办法重构了一个吧,我在做一样事情,里面的很多component不能直接放去asyncio里面
遇到相同的需求,请问两位有解决的方案吗? @AgingChan @JimLee1996
@MAhaitao999 我自己写了一个
欢迎提PR到这个仓库, 我可以帮忙review
作者你好,项目非常实用,也写的非常好。
最近我在配合aiokafka+asyncio+service_streamer的时候遇到了问题,即调用streamer的时候发生了阻塞,streamer的输出日志中,导致每个task的batch为1。
我的疑惑如下:
问题的原因是不是因为streamer的实现是针对多线程(比如flask)或者多进程的,对于原生的python协程而言,会阻塞掉当前的loop。
有没有什么比较好的方法或者小trick可以解决这个问题
希望你帮忙看看并提些建议吧,谢谢~