简体   繁体   中英

Chromedriver text file busy

I have an app that runs selenium and does some testing. when I run my code in stand-alone, it works perfectly. But when I run it several times, to test multiple things in the same time, I get an error.

Here is my code:

    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument("window-size=1920,1080")
    chrome_options.add_argument("--disable-features=NetworkService")
    driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
    driver.get(URL)

and here's the error

    files = self.__unpack(file_path)
    File "/usr/local/lib/python3.6/dist-packages/webdriver_manager/driver_cache.py", line 99, in __unpack
    return extract_zip(path, to_directory)
    File "/usr/local/lib/python3.6/dist-packages/webdriver_manager/archive.py", line 7, in extract_zip
    archive.extractall(to_directory)
    File "/usr/lib/python3.6/zipfile.py", line 1524, in extractall
    self._extract_member(zipinfo, path, pwd)
    File "/usr/lib/python3.6/zipfile.py", line 1578, in _extract_member
    open(targetpath, "wb") as target:
    OSError: [Errno 26] Text file busy: '/home/root/.wdm/drivers/chromedriver/80.0.3987.106/linux64/chromedriver'

my understanding is that there is an instance of chromedriver which is already running, which is possible as I can run this code in the background. How can I handle this error?

I believe you are right: the error happens when there is already an instance of chrome running.

To fix first find the processes running chrome . You can do this by search processes which contain the name chrome like so:

pidof chrome

Then you can kill all of them like so:

pkill -f chrome

Re-running your code afterwards should not produce this error.

I meet this error recently, I tried "rsync" to copy the chromedriver to a new directory, then update the environment variable to the new path, and it works.

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