0

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

1
  • You can use with as context manager like it is used in files opening and it will automatically closes the session just like file. Commented Dec 9, 2019 at 9:58

1 Answer 1

1

You might want to try closing the session:

session = HTMLSession()
session.close()

See requests_html.HTMLSession.close.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.