or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/invoke@2.2.x
tile.json

tessl/pypi-invoke

tessl install tessl/pypi-invoke@2.2.0

Pythonic task execution library for managing shell-oriented subprocesses and organizing executable Python code into CLI-invokable tasks

Agent Success

Agent success rate when using this tile

96%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.25x

Baseline

Agent success rate without this tile

77%

task.mdevals/scenario-3/

Background Task Manager

Build a task automation system that can execute multiple long-running background tasks concurrently and collect their results. The system should support starting tasks asynchronously, monitoring their progress, and waiting for their completion.

Requirements

Core Functionality

Implement a TaskManager class that can:

  1. Execute shell commands as background tasks without blocking
  2. Track multiple running background tasks
  3. Wait for and collect results from all background tasks
  4. Support executing a background task and automatically cleaning up when done

Task Execution

The system should be able to:

  • Start a long-running command (e.g., sleep 2 && echo "Task complete") without blocking
  • Continue execution while the background task runs
  • Join back to the background task to get its result

Multiple Task Management

When managing multiple tasks:

  • Start multiple background tasks concurrently
  • Execute other work while tasks run in the background
  • Wait for all tasks to complete and collect their outputs

Context-Based Execution

Support running a background task using a context manager pattern where:

  • A task starts when entering the context
  • Other work can be done within the context
  • The task is automatically joined when exiting the context

Implementation

@generates

API

class TaskManager:
    """Manages asynchronous task execution using shell commands."""

    def __init__(self, context):
        """
        Initialize the task manager.

        Args:
            context: The execution context for running commands
        """
        pass

    def start_task(self, command):
        """
        Start a command as a background task without blocking.

        Args:
            command: Shell command to execute

        Returns:
            A promise object representing the running task
        """
        pass

    def run_tasks_parallel(self, commands):
        """
        Execute multiple commands concurrently and collect all results.

        Args:
            commands: List of shell commands to execute

        Returns:
            List of results in the same order as commands
        """
        pass

    def run_with_background_task(self, background_cmd, foreground_cmd):
        """
        Execute a background command using context manager pattern while
        running a foreground command, automatically cleaning up the background task.

        Args:
            background_cmd: Command to run in background
            foreground_cmd: Command to run in foreground

        Returns:
            Tuple of (background_result, foreground_result)
        """
        pass

Test Cases

Single Background Task

  • Starting a background task with a 1-second sleep returns immediately without blocking, then joining the task returns the expected output @test

Multiple Parallel Tasks

  • Starting three background tasks (with different sleep durations) and joining them all returns outputs in the correct order @test

Context Manager Pattern

  • Running a background server task using context manager automatically cleans up after the foreground work completes @test

Dependencies { .dependencies }

invoke { .dependency }

Provides task execution and automation support.