• Stars
    star
    510
  • Rank 86,011 (Top 2 %)
  • Language
    Python
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Runs things in the background.

Background

It runs stuff in the background.

"An elegant decorator-based abstraction around Python 3's concurrent.futures ThreadPoolExecutor class"

β€”Simon Willison

This module makes it stupidly simple to run things in the background of your application, be it a CLI app, or a web app.

Basic Usage

import time

import background


@background.task
def work():
    # Do something expensive here.
    time.sleep(10)


for _ in range(100):
    work()

Advanced Usage

import time

import background

# Use 40 background threads.
background.n = 40


@background.task
def work():
    time.sleep(10)
    return "Done!"

@background.callback
def work_callback(future):
    print(future.result())


for _ in range(100):
    work()

Installation

$ pipenv install background
✨🍰✨