Maifee Ul Asad
Maifee Ul Asad

Reputation: 4577

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

Upvotes: 0

Views: 304

Answers (1)

Dan D.
Dan D.

Reputation: 74675

You might want to try closing the session:

session = HTMLSession()
session.close()

See requests_html.HTMLSession.close.

Upvotes: 1

Related Questions