MCPcopy Index your code
hub / github.com/shareAI-lab/learn-claude-code / start_background_task

Function start_background_task

s16_team_protocols/code.py:287–308  ·  view source on GitHub ↗

Run tool in a daemon thread. Returns background task ID.

(block)

Source from the content-addressed store, hash-verified

285
286
287def start_background_task(block) -> str:
288 """Run tool in a daemon thread. Returns background task ID."""
289 global _bg_counter
290 _bg_counter += 1
291 bg_id = f"bg_{_bg_counter:04d}"
292 cmd = block.input.get("command", block.name)
293
294 def worker():
295 result = execute_tool(block)
296 with background_lock:
297 background_tasks[bg_id]["status"] = "completed"
298 background_results[bg_id] = result
299
300 with background_lock:
301 background_tasks[bg_id] = {
302 "tool_use_id": block.id,
303 "command": cmd,
304 "status": "running",
305 }
306 threading.Thread(target=worker, daemon=True).start()
307 print(f" \033[33m[background] dispatched {bg_id}: {cmd[:40]}\033[0m")
308 return bg_id
309
310
311def collect_background_results() -> list[str]:

Callers 1

agent_loopFunction · 0.70

Calls 1

getMethod · 0.45

Tested by

no test coverage detected