Skip to main content

Simple async w/o async

Project description

multitasking: Simple async w/o async

multitasking offers a simple method to convert Python methods into asynchronous / non-blocking methods by using decorators.

Example

import multitasking
import time
import random

import signal

# kill all tasks on ctrl-c
signal.signal(signal.SIGINT, multitasking.killall)

# to wait for task to finish, use:
# signal.signal(signal.SIGINT, multitasking.wait_for_tasks)

@multitasking.task
def hello(count):
    sleep = random.randint(1,10)/2
    print("Hello %s (sleeping for %ss)" % (count, sleep))
    time.sleep(sleep)
    print("Goodbye %s (after for %ss)" % (count, sleep))


if __name__ == "__main__":
    for i in range(0, 10):
        hello(i+1)

Installation

Install multitasking using pip:

$ pip install multitasking --upgrade --no-cache-dir

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multitasking-0.0.1.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file multitasking-0.0.1.tar.gz.

File metadata

File hashes

Hashes for multitasking-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7c084bd009050453c624d9dab8a03fc744b91a58d0e03ed9d79ca75f1a7ee465
MD5 6008742767e6ff6855f817a8afbcf145
BLAKE2b-256 ac770d788812253204f7fd914ee5b7b8e0a8da6267a47cbd5e4381b3a87133ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page