Kill Chromium processes properly to avoid defunct/zombie processes

This commit is contained in:
ngosang 2023-01-06 13:58:24 +01:00
parent 4807e9dbe2
commit 7d84f1b663
4 changed files with 12 additions and 4 deletions

View File

@ -2,6 +2,7 @@
## v3.1.0 (upcoming)
* Kill Chromium processes properly to avoid defunct/zombie processes
* Include procps (ps), curl and vim packages in the Docker image
## v3.0.0 (2023/01/04)

View File

@ -29,7 +29,8 @@ RUN dpkg -i /libgl1-mesa-dri.deb \
&& dpkg -i /adwaita-icon-theme.deb \
# Install dependencies
&& apt-get update \
&& apt-get install -y --no-install-recommends chromium chromium-common chromium-driver xvfb procps curl vim \
&& apt-get install -y --no-install-recommends chromium chromium-common chromium-driver xvfb dumb-init \
procps curl vim \
# Remove temporary files and hardware decoding libraries
&& rm -rf /var/lib/apt/lists/* \
&& rm -f /usr/lib/x86_64-linux-gnu/libmfxhw* \
@ -52,6 +53,9 @@ COPY package.json ../
EXPOSE 8191
# dumb-init avoids zombie chromium processes
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["/usr/local/bin/python", "-u", "/app/flaresolverr.py"]
# Local build

View File

@ -599,7 +599,8 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
def quit(self):
logger.debug("closing webdriver")
if hasattr(self, "service") and getattr(self.service, "process", None):
self.service.process.kill()
self.service.process.terminate()
self.service.process.wait(5)
try:
if self.reactor and isinstance(self.reactor, Reactor):
logger.debug("shutting down reactor")

View File

@ -27,12 +27,14 @@ def start_detached(executable, *args):
reader, writer = multiprocessing.Pipe(False)
# do not keep reference
multiprocessing.Process(
process = multiprocessing.Process(
target=_start_detached,
args=(executable, *args),
kwargs={"writer": writer},
daemon=True,
).start()
)
process.start()
process.join()
# receive pid from pipe
pid = reader.recv()
REGISTERED.append(pid)