GithubHelp home page GithubHelp logo

pyrunner's Introduction

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.

pyrunner's People

Contributors

cdancette avatar

Stargazers

 avatar Luidiblu avatar Ronan Riochet avatar dai avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

thewchan

pyrunner's Issues

python library

Provide a python library to do basic tasks that could work in a standalone way (without creating a Task object)

functions to create:

  • creating a .running token (function that will verify if running, and if not return create token and return True).
    Can also check if done
  • check if task is done
  • create .done token

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.