并行进程或线程中的python asyncio任务

时间:2019-08-06 06:24:35

标签: python-3.x python-asyncio concurrent.futures

我试图在并行进程或线程中运行异步任务,以便每次调用for循环时都在单独的线程或进程上调用该调用,我是asyncio / futures模块的新手,而且我很难是时候联系我的思考过程了,请提出任何澄清的问题来解决这个问题。

from concurrent.futures import ThreadPoolExecutor
import asyncio

async def clean_up_process_wrapper(app):
    loop = asyncio.get_event_loop()
    while app.is_running:
        await(sleep(0.1))
        for system_name, system_object in app['State_Machine_Container'].items():
            try:
                await loop.run_in_executor(None, app['State_Machine_Container'][system_name]['start_cleanup_process'])
            except RuntimeError:
                pass

跟踪::

await loop.run_in_executor(None, app['State_Machine_Container'][system_name]['start_cleanup_process'])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 638, in run_in_executor
    self._check_callback(func, 'run_in_executor')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 593, in _check_callback
    "coroutines cannot be used with {}()".format(method))
TypeError: coroutines cannot be used with run_in_executor()

0 个答案:

没有答案