'Selenium - Why is some windows closing by itself while program not finished?

When I run the test.py file, windows open as many times as I want, it can log in and execute the necessary commands. But every time, random tabs closing by themselves without throw any errors. The program continuing to run and open windows. Especially the first opened window never closing. I've searched everywhere. But I couldn't find any useful information. I want to open a specified number of windows without closing any windows. Thank you in advance for your help.

testmdl.py:

from selenium.webdriver.common.by import By
from time import sleep
import undetected_chromedriver.v2 as uc
from fake_useragent import UserAgent

try:
    ua = UserAgent()
    userAgent = ua.random
except:
    ua = UserAgent()
    userAgent = ua.random 

class Main(): 

    def get_chromedriver(self):
        chrome_options = uc.ChromeOptions()
        #chrome_options.add_argument('--proxy-server=%s' % PROXY)
        #options.add_experimental_option("detach", True)
        chrome_options.add_argument(f'user-agent={userAgent}')
        driver = uc.Chrome(options=chrome_options,version_main=101)
        return driver

    def session(self, link, username, passsword):
        driver = self.get_chromedriver()
        driver.maximize_window()
        driver.get(link)
        driver.implicitly_wait(30)
        sleep(5)
        #codes
        #codes
        #codes
        #if i + 1 > j:
            #sleep(3000000)
            #driver.quit()

test.py:

from time import sleep
from testmdl import Main

usernamelist = ["username", "username1"]
passwordlist = ["password", "password1"]

urll = open("path")
link = urll.read()
trgtlink = link.strip()

if __name__ == "__main__":
    i = 0
    j = len(usernamelist) - 1 
    while True:
        if i <= j:
            p = Main()
            p.session(trgtlink, usernamelist[i], passwordlist[i])
            i = i + 1
        else:
            sleep(3000000)
            i = 0


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source