Closed dnguyenSL closed 7 months ago
Does using this function works
import subprocess
import platform
def kill_process_by_pid(pid):
if pid is None:
raise ValueError("A PID must be provided")
os_name = platform.system()
try:
if os_name == 'Windows':
subprocess.run(['taskkill', '/PID', str(pid), '/F'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else: # macOS and Linux share the same command for killing a process by PID
subprocess.run(['kill', str(pid)], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except subprocess.CalledProcessError:
print(f"Process with PID {pid} could not be terminated or does not exist.")
except Exception as e:
print(f"An error occurred while trying to kill the process with PID {pid}: {e}")
# Example usage:
# kill_process_by_pid(driver.service.process.pid) # Replace 12345 with the actual PID you want to kill
Also, let me know is the issue due to stealth driver only, or normal driver works fine?
Good morning, I encountered the same issue. The issue stems from the stealth driver, which initiates a Chrome process but fails to close it properly.
I resolved this issue locally by ensuring the termination of the Chrome process at the end of each iteration with the kill_process_by_pid()
method, simultaneously with the execution of the driver's quit()
method.
To implement this solution, I modified the do_create_stealth_driver()
method in create_stealth_driver.py
file to record the PID as follows: remote_driver.chrome_driver = chrome.pid
@VincentDoreau13 and @dnguyenSL, I have released a bug fix, Kindly run
python -m pip install botasaurus --upgrade
And @VincentDoreau13 could you let me know if this fix resolves the issue?
It's good for me, the problem is solved ! Thanks !
Hi omkarcloud, I really appreciate your project in solving CloudFlare detection.
Context
scrape_cookies
) with my provided proxy providers and particular urls. However browsers are not close properly after finishing.python -m botasaurus.close
in your suggestion because it interrupts concurrent requests.I tried these approaches but none of these work:
driver.close()
: close the browser but not the Chrome instance.driver.quit()
: this method doesn't work at all. Here is my change indecorators.py
.os.kill(driver.service.process.pid, 9)
driver.server.process.kill()
driver.server.process.terminate()
Do you have any suggestion for me?
Environment 1:
OS: MacOS Proxy: datacenter IPs. The library closed the browsers but not the instances.
Environment 2:
OS: Docker on Mac Dockerfile: Based on this botasaurus-starter. Proxy: datacenter IPs. Memory Usage: keeps going up after requests.
My code: