Skip to main content

pyrunner

A simple Python task runner. Use it as a CLI, or wrap your own scripts with the python interface.

Features

  • Prevent a task to be running twice simultaneously.
  • Prevent a task to be launched again when it is already completed.

It implements this by writing token files .done and .running in a specified task directory. One directory = One task.

Example use cases

Crash recovery

Say you launched multiple tasks for all subdirectories: ls | xargs -I % command %, and the command crashes in the middle. Now how do you run only the unfinished tasks ?

You can use pyrunner to run the your tasks, and then the second run will only start unfinished tasks.

Parallel

It can also be used as a poor man's parallel library. Instead of ls | xargs -P 2 -I % command % you can run ls | xargs -I % pyrunner %/.tokens command % in two shells. Each shell will pick up the pending tasks.

Installation

pip install pyrunner

CLI usage

You can use it as a cli, like this :

pyrunner <tokens-folder> <command>

For example

pyrunner .tokens/ touch file.txt

Will create a file called file.txt.

Another example :

pyrunner .tokens/ bash -c "date > date.txt"

This command will save the current date in the file date.txt. If you run it again it will not run.

Python Usage

You can also wrap your script in a python class. The advantage is that you can define your own arguments, and use them to define the tokens folder. (and avoid duplicating it as an argument like with the pyrunner cli).

For this, you need to wrap your script in a python class.

A basic task that creates a file

from pyrunner import Task

class TouchTask(Task):

    def command(self):
        return "touch"

    def experiment_folder(self, args):
        return "." # return current folder

if __name__ == "__main__":
    TouchTask().run()

More complex examples are in the examples/ directory.

Metadata

Release files for pyrunner 0.1.4

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

Source distribution (sdist)

Source distribution for pyrunner 0.1.4
File Size Uploaded
pyrunner-0.1.4.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyrunner 0.1.4
File Interpreter ABI Platform
pyrunner-0.1.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 7.7 kB

Release files / pyrunner-0.1.4.tar.gz

Download URL pyrunner-0.1.4.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2f00ab841465bb394c5a2eed8e16b4d2075ea5aabfd6143aaafa6802690541c4
BLAKE2b-256 checksum
How to use checksums
817bdd7f13c4bc3dc3720f048c6afdd9459ebaf8502cee9ca7a13687e986f80f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pyrunner-0.1.4-py2.py3-none-any.whl

Download URL pyrunner-0.1.4-py2.py3-none-any.whl
Size 3.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5de1c5552767c5e240cc93e67b22855b8b368dfeca724d0f472f80cfa198face
BLAKE2b-256 checksum
How to use checksums
bcaa9f2f98ef1afc994341cb216b29ee3c406be054b76a883efaeadc9ed9bf63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

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