简体   繁体   中英

python kill python's sub-process

I'm using requests_html to scrape some site :

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. 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

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

You might want to try closing the session:

session = HTMLSession()
session.close()

See requests_html.HTMLSession.close .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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