Python Asyncio和multiprocessing.Process-如何传递协同路由?

Python Asyncio和multiprocessing.Process-如何传递协同路由?,python,python-3.x,python-multiprocessing,python-asyncio,Python,Python 3.x,Python Multiprocessing,Python Asyncio,我有一个协同程序正在抓取一些数据。我正在尝试添加多处理以加快速度。我想到了使用multiprocessing.Process。我的合作项目叫做“获取学生页面” 我试图做的是将此协同程序作为目标传递给Process类: def fetch_students_concurrently(self): for _ in range(10): Process(target=self.fetch_students_pages).start() 但如果在以下方

我有一个协同程序正在抓取一些数据。我正在尝试添加多处理以加快速度。我想到了使用multiprocessing.Process。我的合作项目叫做“获取学生页面”

我试图做的是将此协同程序作为目标传递给Process类:

    def fetch_students_concurrently(self):
        for _ in range(10):
            Process(target=self.fetch_students_pages).start()
但如果在以下方面失败:

/usr/lib/python3.7/multiprocessing/process.py:99:RuntimeWarning:coroutine“StudentPageParser.fetch\u students\u pages”从未等待过 self._target*self._args,**self._kwargs RuntimeWarning:启用tracemalloc以获取对象分配回溯

是否有办法等待它或使用另一种解决方案?

考虑改用map:


您不应以这种方式混合进程和协同路由-协同路由由事件循环管理此返回-AttributeError:无法pickle本地对象“WeakSet.\uuu init.\uuu..\u remove”。事实上,每次我尝试使用Pool/processPoolExecutor时,这个错误都会出现多次。是的,我承认这是使用多处理的一个缺点。在调用map时定义了一个难以序列化的对象。您的应用程序庞大而复杂。启动一个非常简单的新应用程序,只需在helper和parent中执行sleep/print操作,即可验证您是否同时拥有多个Worker。然后构建它,从原始应用程序添加更多内容,直到它崩溃。考虑在助手中创建对象,而不是在父对象中创建对象。考虑推迟复杂的导入语句,直到帮助器已经开始运行。
cores = 8

with Pool(cores) as p:
    p.map(self.fetch_students_pages, range(cores))