python kill python的子进程

问题描述 投票:0回答:1

我正在使用requests_html抓取某些网站:

from requests_html import HTMLSession
    for i in range (0,30):
    session = HTMLSession()
    r = session.get('https://www.google.com')
    r.html.render()
    del session

现在,此代码创建了30个以上的chromium子过程作为Python的子过程。这样就获得了内存,那么如何删除它们呢?

我不想使用psutil,因为它会增加一个依赖关系并杀死python的子进程python可能有一些内置方法,如果有的话,我想得到启发]] >

我什至不能使用exit(),因为我必须先返回然后再退出(在方法内部),当然我也不能退出并返回

我正在使用requests_html抓取某些网站:从request_html导入范围为(0,30)的i的HTMLSession:session = HTMLSession()r = session.get('https://www.google.com')r .html ....

python
1个回答
0
投票

您可能想尝试关闭会话:

© www.soinside.com 2019 - 2024. All rights reserved.