import concurrent.futures
import asyncio
loop = asyncio.get_event_loop()
executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
sgdata = await self.loop.run_in_executor(self.executor, GetDate)
ai_run = await self.loop.run_in_executor(self.executor, RunFrountent, self.sgdata)
def model_load_and_predict(self):
"""load model and predict"""
t1 = Process(target=self.ai_run.predict)
t1.daemon = True
t1.start()
return t1.pid
pids['result'] = await loop.run_in_executor(executor, self.model_load_and_predict)
asyncio中使用线程,在该线程中使用进程
最新推荐文章于 2024-03-15 16:13:35 发布