Skip to main content

batch_queue2

batch_queue2 is a simple task queuing system built using Python's asyncio. It allows you to submit, manage, and track tasks using a lightweight, XML-RPC-based interface. It's main purpose is to allow queueing up more tasks to run on the local machine than we can support running simultaneously; either because the number of tasks is more than the number of CPUs or because running all those tasks simultaneously will use too much memory.

Features

  • Submit, list, suspend, resume, and kill tasks using command-line commands.
  • Tasks can be queued, paused, or resumed based on available CPUs.
  • XML-RPC server for managing task requests.
  • Ability to run tasks using multiple CPUs.
  • Tasks can be paused and resumed.

Requirements

  • Python 3.7+
  • aiohttp
  • requests

Installation

You can install batch_queue2 from PyPI:

pip install batch_queue2

Or clone the repository from Sourcehut:

hg clone https://hg.sr.ht/~ndbecker2/batch_queue2
cd batch_queue2
python -m pip install .

Usage

After installing, you can use the batch_queue command to manage tasks. Below are the available options:

Starting the Server

To start the server:

batch_queue start --max-cpus 4
  • --max-cpus: (Optional) Specify the maximum number of CPUs to use. Defaults to the number of CPUs available on your system.

The server will start in daemon mode by default.

Submitting a Task

To submit a task, use the submit command:

batch_queue submit <command>

For example:

batch_queue submit sleep 10

You can also optionally specify:

  • --log-stdout <file>: Redirect the standard output of the task to a file.
  • --log-stderr <file>: Redirect the standard error of the task to a file.

Listing Tasks

To list all tasks:

batch_queue list

This will display:

  • Max CPUs available.
  • Active tasks.
  • Queued tasks.
  • Paused tasks.
  • Runnable paused tasks.

Suspending and Resuming Tasks

To suspend task(s) (running or queued):

batch_queue suspend <task_ids>

To resume a paused task(s):

batch_queue resume <task_ids>

Killing Task(s)

To kill specific task(s):

batch_queue kill <task_ids> <signal>

You can also optionally specify the signal to use, default is SIGTERM.

Getting Task Information

To get detailed information about a specific task:

batch_queue id <task_id>

This command provides detailed information about the task including command, user, working directory, environment variables, and logs.

Change #cpus

You can reset the max #cpus. When you do this, if the new maximum is greater than the number of active tasks the scheduler is recalled and queued tasks can be started. If the new maximum is smaller than the number of active tasks tasks will be suspended, but marked runnable to be continued later.

batch_queue setcpus #cpus

Stopping the Server

To stop the server:

batch_queue stop

This command gracefully stops the server, ensuring no tasks are left in a zombie state.

Example Workflow

  1. Start the server using:

    batch_queue start --max-cpus 4
    
  2. Submit a couple of tasks:

    batch_queue submit sleep 10
    batch_queue submit echo "Hello World"
    
  3. List the tasks to see the active, queued, and paused tasks:

    batch_queue list
    
  4. Suspend running tasks:

    batch_queue suspend 0
    
  5. Resume paused tasks:

    batch_queue resume 0
    
  6. Stop the server:

    batch_queue stop
    

Logging

The server logs all activity to ~/batch_queue.log. You can view the log to monitor task submissions, task status changes, server starts and stops, etc.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Security

The server listens on a unix domain socket normally in the user's home directory who starts it. Only users with access to this socket can use it.

Release files for batch-queue2 1.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for batch-queue2 1.0.12
File Size Uploaded
batch_queue2-1.0.12.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for batch-queue2 1.0.12
File Interpreter ABI Platform
batch_queue2-1.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 22.0 kB

Release files / batch_queue2-1.0.12.tar.gz

Download URL batch_queue2-1.0.12.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ba05e3e7d74b17be3ee197723368d4e5eb4e5900d5fbe0d574933d1e7ab1bbde
BLAKE2b-256 checksum
How to use checksums
ff785d29fa91695167cfbd42b186da11a1bc68572c1080313f6f9ebd1b5af4d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / batch_queue2-1.0.12-py3-none-any.whl

Download URL batch_queue2-1.0.12-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28ef5f8c4051c0f2f36b1a44ff660e6c844509b5f4390017f76c88c51cfd7cb8
BLAKE2b-256 checksum
How to use checksums
467f9e0bb57aef5d4772b4589a7b46b70d58c327e3f720c973a4c80f2e1c137e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

1.0.12 This release

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.4

2 release files

1.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page