I am trying to run two separate instances of the Tor Browser using Selenium in Python, but in two different scripts. I have set up two fresh Tor Browser installations and modified the torrc file in each installation to use different ports.
Each instance works perfectly fine when run individually. However, when I try to start them simultaneously, the second instance fails with the following error:
“Tor exited during startup. This might be due to an error in your torrc file, a bug in Tor or another program on your system, or faulty hardware. Until you fix the underlying problem and restart Tor, Tor Browser will not start.” error
I have a freshly installed Windows 11 system with only Python 3 and AnyDesk installed.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
tor_path = r'C:Tor BrowserBrowserfirefox.exe'
firefox_options = Options()
firefox_options.binary_location = tor_path
driver = webdriver.Firefox(options=firefox_options)
WebDriverWait(driver, 300).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="connectButton"]'))
)
driver.find_element(By.XPATH, value= '//*[@id="connectButton"]').click()
For the second script, I copied the first one and changed the path to the second Tor installation’s firefox.exe.
I made sure that both scripts use different ports by connecting them one after the other and checking if the port is in use. The script that is started second doesn’t even try to connect because there are no logs generated.Checked if they use different ports