简体   繁体   English

python 杀死python的子进程

[英]python kill python's sub-process

I'm using requests_html to scrape some site :我正在使用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

Now this code creates more than 30 sub-process of chromium as Python 's sub-process.现在这段代码创建了 30 多个Chromium子进程作为Python的子进程。 And this acquires memory, so how can I remove them?这会获得内存,那么我该如何删除它们呢?

I don't want to use psutil , as it will increase one more dependency and to kill python's sub-process python may have some built in method, I want to be enlightened, if there is so我不想使用psutil ,因为它会增加一个更多的依赖并杀死 python 的子进程 python 可能有一些内置的方法,如果有的话,我想开悟

I can't even use exit() as I have to return and then exit(inside a method), and of course I can't exit and return我什至不能使用 exit() 因为我必须返回然后退出(在方法内),当然我不能退出并返回

You might want to try closing the session:您可能想尝试关闭会话:

session = HTMLSession()
session.close()

See requests_html.HTMLSession.close .请参阅requests_html.HTMLSession.close

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM