Git Product home page Git Product logo

Comments (4)

cbgz121 avatar cbgz121 commented on May 23, 2024 1

set this option option = uc.ChromeOptions() option.add_argument("--disable-gpu") driver = uc.Chrome(options=option)

I tried that and it did not work. Chrome processes are still open in the background. 19ELPGi

you can try this #1767 #1723

from undetected-chromedriver.

cbgz121 avatar cbgz121 commented on May 23, 2024

set this option
option = uc.ChromeOptions() option.add_argument("--disable-gpu") driver = uc.Chrome(options=option)

from undetected-chromedriver.

PostMalone avatar PostMalone commented on May 23, 2024

set this option option = uc.ChromeOptions() option.add_argument("--disable-gpu") driver = uc.Chrome(options=option)

I tried that and it did not work. Chrome processes are still open in the background.
19ELPGi

from undetected-chromedriver.

PostMalone avatar PostMalone commented on May 23, 2024

Thank you for linking me #1767 (comment)

I "fixed" my problem with the help of their code.

Now after my Bot executes the driver.quit() - it also terminates the chrome.exe processes.

I fixed by adding this:

def cleanup_processes(self):
    try:
       
        tasks = subprocess.check_output(['tasklist'], encoding='utf-8')

       
        if 'chrome.exe' in tasks:
            subprocess.run(["taskkill", "/F", "/IM", "chrome.exe", "/T"], check=True)
            logging.info("Chrome processes killed.")
        else:
            logging.info("No Chrome processes found.")

       
        if 'chromedriver.exe' in tasks:
            subprocess.run(["taskkill", "/F", "/IM", "chromedriver.exe", "/T"], check=True)
            logging.info("Chromedriver processes killed.")
        else:
            logging.info("No Chromedriver processes found.")

    except subprocess.CalledProcessError as e:
        logging.error(f"Error checking or killing processes: {e}")

And then:

logging.basicConfig(filename='twitter_bot.log', level=logging.INFO, format='%(asctime)s - %(levelname)s: %(message)s')

twitter_bot = TwitterBot()

try:
    while True:
        twitter_bot.sendReply()

        # Increment the iteration count
        twitter_bot.iteration_count += 1

        # Check if the restart condition is met
        if twitter_bot.iteration_count >= twitter_bot.restart_interval:
            print(f'Restarting session after {twitter_bot.restart_interval} iterations...')
            twitter_bot.driver.quit()  # Close the current session
            time.sleep(twitter_bot.sleepTime * 2)
            twitter_bot.cleanup_processes()  # Cleanup Chrome and Chromedriver processes
            twitter_bot = TwitterBot()  # Start a new session
            twitter_bot.iteration_count = 0

except Exception as e:
    logging.error(f'Something went wrong: {e}. Restarting browser session...')
    twitter_bot.driver.quit()  # Close the current session
    time.sleep(twitter_bot.sleepTime * 2)
    twitter_bot.cleanup_processes()  # Cleanup Chrome and Chromedriver processes
    twitter_bot = TwitterBot()  # Start a new session

from undetected-chromedriver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.