Skip to content

Commit

Permalink
Merge pull request #184 from plotly/andrew/cleanup-improvement
Browse files Browse the repository at this point in the history
Andrew/cleanup improvement
  • Loading branch information
ayjayt authored Jan 28, 2025
2 parents f0e9d56 + b3b2dcf commit fc68b69
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions choreographer/browser_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,23 @@ async def _is_closed(self, wait: int | None = 0) -> bool:

async def _close(self) -> None:
if await self._is_closed():
_logger.debug("No _close(), already is closed")
return

try:
await self.send_command("Browser.close")
except (BrowserClosedError, BrowserFailedError):
_logger.debug("Browser is closed trying to send Browser.close")
return
except ChannelClosedError:
pass
_logger.debug("Can send browser.close on close channel")

await asyncio.to_thread(self._channel.close)

if await self._is_closed():
_logger.debug("Browser is closed after closing channel")
return

_logger.info("Must kill browser.")
await asyncio.to_thread(kill, self.subprocess)
if await self._is_closed(wait=4):
return
Expand All @@ -206,7 +209,7 @@ async def close(self) -> None:
_logger.info("Broker cleaned up.")
if self._logger_pipe:
os.close(self._logger_pipe)
_logger.info("Logging pipe closed.")
_logger.info("Logging pipe closed.")
self._channel.close()
_logger.info("Browser channel closed.")
self._browser_impl.clean() # threading this just seems to cause problems
Expand Down
11 changes: 7 additions & 4 deletions choreographer/utils/_tmpfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ def remove_readonly(
_logger.info(f"shutil.rmtree() failed to delete temporary file. Error {e}")

def extra_clean() -> None:
_logger.info("Extra manual clean waiting 3 seconds.")
time.sleep(1)
_logger.info("Extra manual clean executing.")
self._delete_manually()
i = 0
tries = 5
while self.path.exists() and i < tries:
time.sleep(1)
_logger.info(f"Extra manual clean executing {i}.")
self._delete_manually()
i += 1

# testing doesn't look threads so I guess we'll block
extra_clean()
Expand Down

0 comments on commit fc68b69

Please sign in to comment.