Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

動いてたseleniumのプロセスが「selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service」いうて動かなくなったら……再起動するかchromeのプロセスを確認する

Raspberry Pi 4B上に組んでいたselemiumのテストをしていたところ、
途中から「selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service」というエラーを吐いて動かなくなりました
テスト中というのがミソで、正体はちゃんと閉じてないchromeがメモリをバカ食いして停止というのが真相。

実際のところ

無難に再起動

当時の状況はこんな感じ。

$ python3 sample.py
start...

Traceback (most recent call last):
  File "sample.py", line 25, in <module>
    driver = webdriver.Chrome(CHROME_DRIVER, options=options)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 104, in start
    raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /usr/lib/chromium-browser/chromedriver

最初の方は途切れ途切れ実行できたり出来なかったりだったのですが、ついには全く動かない事態に。

もしやと思い再起動をかけたら……動きました。
おそらく、chromiumのメモリがバカ食いしていたのが原因です。

【2021/10/01追記】どうしても再起動が嫌ならpkill

AWS LightSailでも同様のケースが生じ、もしやと思いpgrepをしたところ……

$ pgrep chromium
1122
1133
...
3199

どうもこいつが正体のようですね。
というわけで、pkillでchromeのプロセスすべてにご退場願います。

$ pkill chromium

で、同じコマンドを起動したら無事に動きましたとさ。めでたしめでたし。