26
from colab_cli.utils import get_status_code
27
28
29
+# Default execute() timeout for human-in-the-loop automations (auth /
30
+# drivemount). The kernel goes silent while the user completes a browser
31
+# OAuth flow, which can routinely take 30s+; the upstream 10s default
32
+# raises ``TimeoutError`` mid-flow even though the mount actually succeeds.
33
+# 10 minutes is long enough for any realistic interactive auth ceremony
34
+# without leaving CI hangs unbounded.
35
+INTERACTIVE_AUTOMATION_TIMEOUT_SEC = 600
36
+
37
+
38
def run_automation(
30
- name: str, op: str, code: str, allow_stdin: bool = False, path: str = None
39
+ name: str,
40
+ op: str,
41
+ code: str,
42
+ allow_stdin: bool = False,
43
+ path: str = None,
44
+ timeout: Optional[float] = None,
45
):
46
from colab_cli.common import state
47
144
else:
145
state.history.log_event(name, "automation", {"op": op, "code": code})
146
133
- outputs = runtime.execute_code(code, allow_stdin=allow_stdin)
147
+ outputs = runtime.execute_code(code, allow_stdin=allow_stdin, timeout=timeout)
148
state.history.log_event(
149
name, "automation_result", {"op": op, "outputs": outputs}
150
)
180
name = state.resolve_session(session)
181
code = "import os\nos.environ['USE_AUTH_EPHEM'] = '0'\nfrom google.colab import auth\nauth.authenticate_user()"
182
typer.echo(f"[colab] Starting Google Auth flow on {name}...")
169
- run_automation(name, "auth", code, allow_stdin=True)
183
+ run_automation(
184
+ name,
185
+ "auth",
186
+ code,
187
+ allow_stdin=True,
188
+ timeout=INTERACTIVE_AUTOMATION_TIMEOUT_SEC,
189
+ )
190
191
192
def drivemount(
201
name = state.resolve_session(session)
202
code = f"from google.colab import drive\ndrive.mount('{path}')"
203
typer.echo(f"[colab] Mounting Google Drive to '{path}' on {name}...")
184
- run_automation(name, "drivemount", code, allow_stdin=True, path=path)
204
+ run_automation(
205
+ name,
206
+ "drivemount",
207
+ code,
208
+ allow_stdin=True,
209
+ path=path,
210
+ timeout=INTERACTIVE_AUTOMATION_TIMEOUT_SEC,
211
+ )
212
213
214
def install(