Properly terminate the selenium browser in Python

Viewed 620

After I finish running the following Python code:

from selenium.webdriver import Firefox
from contextlib import closing

with closing(Firefox()) as browser:
  # some code here

There are still listening geckodriver processes in my Linux machine.

$ ss -arp
LISTEN      0      128                                                    localhost:44132                                                           *:*        users:(("geckodriver",21698,3))
LISTEN      0      128                                                    localhost:57893                                                           *:*        users:(("geckodriver",20242,3))
LISTEN      0      128                                                    localhost:34439                                                           *:*        users:(("geckodriver",19440,3))
LISTEN      0      128                                                    localhost:35435                                                         

How to adjust the Python code, so that it will terminate the processes as well?

1 Answers
Related