Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andrew/cleanup improvement #184

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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