Skip to content

Commit 764e853

Browse files
authoredFeb 24, 2025
Merge pull request #219 from plotly/andrew/add_is_isolated
Add function to determine if isolated
2 parents 6de2b11 + 1e60ebd commit 764e853

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed
 

‎choreographer/browser_async.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def __init__(
110110
parser=parser,
111111
)
112112

113+
def is_isolated(self) -> bool:
114+
"""Return if process is isolated."""
115+
return self._browser_impl.is_isolated()
116+
113117
async def open(self) -> None:
114118
"""Open the browser."""
115119
_logger.info("Opening browser.")
@@ -240,10 +244,11 @@ async def __aexit__(
240244
async def _watchdog(self) -> None:
241245
with warnings.catch_warnings():
242246
warnings.filterwarnings("ignore", category=TmpDirWarning)
243-
_logger.debug("Starting watchdog")
247+
_logger.debug("In watchdog")
244248
loop = asyncio.get_running_loop()
249+
_logger.debug2("Running wait.")
245250
await loop.run_in_executor(None, self.subprocess.wait)
246-
_logger.warning("Browser is being closed by watchdog.")
251+
_logger.warning("Wait expired, Browser is being closed by watchdog.")
247252
self._watch_dog_task = None
248253
await self.close()
249254
await asyncio.sleep(1)

‎choreographer/browsers/_interface_type.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ def get_popen_args(self) -> Mapping[str, Any]: ...
2525
def get_cli(self) -> Sequence[str]: ...
2626
def get_env(self) -> MutableMapping[str, str]: ...
2727
def clean(self) -> None: ...
28+
def is_isolated(self) -> bool: ...

‎choreographer/browsers/chromium.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,24 @@ def __init__(
148148
if not isinstance(channel, Pipe):
149149
raise NotImplementedError("Websocket style channels not implemented yet.")
150150

151+
self._is_isolated = "snap" in str(self.path)
152+
151153
self.tmp_dir = TmpDirectory(
152154
path=self._tmp_dir_path,
153-
sneak="snap" in str(self.path),
155+
sneak=self._is_isolated,
154156
)
155157
_logger.info(f"Temporary directory at: {self.tmp_dir.path}")
156158

159+
def is_isolated(self) -> bool:
160+
"""
161+
Return if /tmp directory is isolated by OS.
162+
163+
Returns:
164+
bool indicating if /tmp is isolated.
165+
166+
"""
167+
return self._is_isolated
168+
157169
def get_popen_args(self) -> Mapping[str, Any]:
158170
"""Return the args needed to runc chromium with `subprocess.Popen()`."""
159171
args = {}

0 commit comments

Comments
 (0)