Properly cleanup chromedriver
This commit is contained in:
parent
827e24acc6
commit
f759f9ddb2
2 changed files with 4 additions and 3 deletions
|
@ -45,7 +45,7 @@ libnss3 \
|
||||||
lsb-release \
|
lsb-release \
|
||||||
xdg-utils
|
xdg-utils
|
||||||
|
|
||||||
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||||
traceroute \
|
traceroute \
|
||||||
iputils-ping \
|
iputils-ping \
|
||||||
dnsutils \
|
dnsutils \
|
||||||
|
|
|
@ -127,11 +127,13 @@ class ScreenshotCog(commands.Cog):
|
||||||
try:
|
try:
|
||||||
await asyncio.to_thread(driver.get, url)
|
await asyncio.to_thread(driver.get, url)
|
||||||
except selenium.common.WebDriverException as e:
|
except selenium.common.WebDriverException as e:
|
||||||
|
await self.bot.loop.run_in_executor(None, driver.quit)
|
||||||
if "TimeoutException" in str(e):
|
if "TimeoutException" in str(e):
|
||||||
return await ctx.respond("Timed out while loading webpage.")
|
return await ctx.respond("Timed out while loading webpage.")
|
||||||
else:
|
else:
|
||||||
return await ctx.respond("Failed to load webpage:\n```\n%s\n```" % str(e.msg))
|
return await ctx.respond("Failed to load webpage:\n```\n%s\n```" % str(e.msg))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
await self.bot.loop.run_in_executor(None, driver.quit)
|
||||||
await ctx.respond("Failed to get the webpage: " + str(e))
|
await ctx.respond("Failed to get the webpage: " + str(e))
|
||||||
raise
|
raise
|
||||||
end_request = time.time()
|
end_request = time.time()
|
||||||
|
@ -165,8 +167,7 @@ class ScreenshotCog(commands.Cog):
|
||||||
|
|
||||||
await ctx.edit(content="Cleaning up...")
|
await ctx.edit(content="Cleaning up...")
|
||||||
start_cleanup = time.time()
|
start_cleanup = time.time()
|
||||||
await asyncio.to_thread(driver.close)
|
await self.bot.loop.run_in_executor(None, driver.quit)
|
||||||
await asyncio.to_thread(driver.quit)
|
|
||||||
end_cleanup = time.time()
|
end_cleanup = time.time()
|
||||||
|
|
||||||
screenshot_size_mb = round(len(await asyncio.to_thread(file.getvalue)) / 1024 / 1024, 2)
|
screenshot_size_mb = round(len(await asyncio.to_thread(file.getvalue)) / 1024 / 1024, 2)
|
||||||
|
|
Loading…
Reference in a new issue