MCPcopy Create free account
hub / github.com/StarsTom/mobileCodexHelper / run_background

Method run_background

mobile_codex_control.py:1358–1383  ·  view source on GitHub ↗
(
        self,
        pending_message: str,
        task: Callable[[], str],
        skip_if_busy: bool = False,
        show_pending: bool = True,
    )

Source from the content-addressed store, hash-verified

1356 return message
1357
1358 def run_background(
1359 self,
1360 pending_message: str,
1361 task: Callable[[], str],
1362 skip_if_busy: bool = False,
1363 show_pending: bool = True,
1364 ) -> None:
1365 if self._busy:
1366 if not skip_if_busy:
1367 self.status_text.set("已有任务进行中,请稍候...")
1368 return
1369
1370 self._busy = True
1371 if show_pending:
1372 self.status_text.set(pending_message)
1373
1374 def worker() -> None:
1375 try:
1376 message = task()
1377 self.root.after(0, lambda: self.status_text.set(message))
1378 except Exception as exc: # noqa: BLE001
1379 self.root.after(0, lambda: self.status_text.set(f"操作失败:{exc}"))
1380 finally:
1381 self.root.after(0, self._mark_idle)
1382
1383 threading.Thread(target=worker, daemon=True).start()
1384
1385 def _mark_idle(self) -> None:
1386 self._busy = False

Callers 3

_build_uiMethod · 0.95
refresh_statusMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected