Skip to content

SB/Driver does not work with ProcessPoolExecutor/ThreadPoolExecutor #2828

Closed
@iamumairayub

Description

@iamumairayub

I have code in my Windows

def send_request(rows, profile):
    
    with SB(
        uc=True,
        ) as sb:
        
        print(f"Opening {row['source']} in thread {profile}")
        sb.driver.uc_open_with_reconnect(row['source'], 10)
    

if __name__ == '__main__':
    
    sessions = 2
    with futures.ProcessPoolExecutor(max_workers=sessions) as executor:

        cursor.execute("SELECT id, source FROM Sale WHERE updated IS NULL LIMIT 2")
        all_jobs=[]
        
        for idx, rows in enumerate(split(cursor.fetchall(), sessions)):
            
            job = executor.submit(
                send_request, 
                rows,
                idx
            )
            all_jobs.append(job)

In logs I can see


Will process 1 rows
Will process 1 rows
Opening https://website.com/url2 in 1
Opening https://website.com/url1 in 0

The URL is opened fine in one of thread/process

I can clearly see browser window

But on the 2nd window its always like this

image

Logs also show

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 170, in _terminate_process
    self.process.terminate()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1573, in terminate
    _winapi.TerminateProcess(self._handle, 1)
OSError: [WinError 6] The handle is invalid
Error terminating service process.
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 170, in _terminate_process
    self.process.terminate()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1573, in terminate
    _winapi.TerminateProcess(self._handle, 1)
OSError: [WinError 6] The handle is invalid

I have tried both ProcessPoolExecutor/ThreadPoolExecutor
I have tried both SB/Driver

Metadata

Metadata

Assignees

No one assigned

    Labels

    UC Mode / CDP ModeUndetected Chromedriver Mode / CDP Modeinvalid usageYou may need to change what you're doing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions