Skip to main content

No project description provided

Project description

autothread_functional_tests

Autothread

Parallelization made easy.

Autothread contains a collection of decorators that make it as easy as possible to add threading or multiprocessing to your projects. Autothread has two types of decorators: blocking and non-blocking.

Non-blocking

Autothreads non-blocking decorators are the easiest way to add threading/multiprocessing to your project. You just need to add a single decorator, which changes your function to calculate in the background instead of blocking the script.

import autothread
import time
from time import sleep as heavyworkload

@autothread.async_threaded() # <-- This is all you need to add
def example(x, y) -> int:
    heavyworkload(1)
    return x*y

start = time.time()
results = []
for i in range(5):
    results.append(example(i, 10)) # the thread is started

print(results) # autothread waits for the thread to end and gives you the result
print("Time expired: ", time.time()-start)
>>> [0, 10, 20, 30, 40]
    Time expired:  1.002363681793213

autothread.async_processed works in the same way but uses multiprocessing instead of threading. More info can be found in the non-blocking README.

Blocking

The blocking decorators of autothread change the function slightly, but give you more control over when the function is executed:

import autothread
import time
from time import sleep as heavyworkload

@autothread.multithreaded() # <-- This is all you need to add
def example(x: int, y: int):
    heavyworkload(1)
    return x*y

@autothread.multiprocessed() # <-- Or to use multiprocessing
def example2(x: int, y: int):
    heavyworkload(1)
    return x*y

Now, instead of integers, your function can take lists of integers. The function will be repeated or each item in your list on a separate thread/process:

start = time.time()
result = example([1, 2, 3, 4, 5], 10)
print(result)
print("Time expired: ", time.time()-start)
>>> [10, 20, 30, 40, 50]
    Time expired:  1.0041766166687012

More info can be found in the blocking README.

Installing

You can install autothread using:

pip install autothread

Or by cloning the source:

git clone https://github.com/Basdbruijne/autothread.git
cd autothread
pip install -e .

Known issues

None at the moment, please open a bug if you run into an issue.

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

autothread-0.0.10.tar.gz (14.5 kB view details)

Uploaded Source

File details

Details for the file autothread-0.0.10.tar.gz.

File metadata

  • Download URL: autothread-0.0.10.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for autothread-0.0.10.tar.gz
Algorithm Hash digest
SHA256 938aab973fdd3c85a58571d6cefc758f7f070a08a451244eedaa0f764a8807fd
MD5 775072877009aeaa90f672dc021f80a9
BLAKE2b-256 4bef9927258f0224c0f20561ec15b3b86d2373cb28cd22f664ba712a393817b1

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