autothread


Nameautothread JSON
Version 0.0.10 PyPI version JSON
download
home_pagehttps://github.com/Basdbruijne/autothread
Summary
upload_time2023-05-09 11:48:57
maintainer
docs_urlNone
authorBas de Bruijne
requires_python
licenseMIT
keywords multithreading multiprocessing decorator
VCS
bugtrack_url
requirements multiprocess psutil tqdm typeguard typing
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![autothread_functional_tests](https://github.com/Basdbruijne/autothread/actions/workflows/main.yml/badge.svg)](https://github.com/Basdbruijne/autothread/actions/workflows/main.yml)

# 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.

```python
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](https://github.com/Basdbruijne/autothread/blob/main/docs/README_non_blocking.md).

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

```python
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:
```python3
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](https://github.com/Basdbruijne/autothread/blob/main/docs/README_blocking.md).

## 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Basdbruijne/autothread",
    "name": "autothread",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "multithreading,multiprocessing,decorator",
    "author": "Bas de Bruijne",
    "author_email": "basdbruijne@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4b/ef/9927258f0224c0f20561ec15b3b86d2373cb28cd22f664ba712a393817b1/autothread-0.0.10.tar.gz",
    "platform": null,
    "description": "[![autothread_functional_tests](https://github.com/Basdbruijne/autothread/actions/workflows/main.yml/badge.svg)](https://github.com/Basdbruijne/autothread/actions/workflows/main.yml)\n\n# Autothread\nParallelization made easy.\n\nAutothread contains a collection of decorators that make it as easy as possible to add\nthreading or multiprocessing to your projects. Autothread has two types of decorators: blocking and non-blocking.\n\n## Non-blocking\nAutothreads non-blocking decorators are the easiest way to add threading/multiprocessing to your\nproject. You just need to add a single decorator, which changes your function to calculate in\nthe background instead of blocking the script.\n\n```python\nimport autothread\nimport time\nfrom time import sleep as heavyworkload\n\n@autothread.async_threaded() # <-- This is all you need to add\ndef example(x, y) -> int:\n    heavyworkload(1)\n    return x*y\n\nstart = time.time()\nresults = []\nfor i in range(5):\n    results.append(example(i, 10)) # the thread is started\n\nprint(results) # autothread waits for the thread to end and gives you the result\nprint(\"Time expired: \", time.time()-start)\n>>> [0, 10, 20, 30, 40]\n    Time expired:  1.002363681793213\n```\n\n`autothread.async_processed` works in the same way but uses multiprocessing instead of threading.\nMore info can be found in the [non-blocking README](https://github.com/Basdbruijne/autothread/blob/main/docs/README_non_blocking.md).\n\n## Blocking\nThe blocking decorators of autothread change the function slightly, but give you more control\nover when the function is executed:\n\n```python\nimport autothread\nimport time\nfrom time import sleep as heavyworkload\n\n@autothread.multithreaded() # <-- This is all you need to add\ndef example(x: int, y: int):\n    heavyworkload(1)\n    return x*y\n\n@autothread.multiprocessed() # <-- Or to use multiprocessing\ndef example2(x: int, y: int):\n    heavyworkload(1)\n    return x*y\n```\n\nNow, instead of integers, your function can take lists of integers. The function will\nbe repeated or each item in your list on a separate thread/process:\n```python3\nstart = time.time()\nresult = example([1, 2, 3, 4, 5], 10)\nprint(result)\nprint(\"Time expired: \", time.time()-start)\n>>> [10, 20, 30, 40, 50]\n    Time expired:  1.0041766166687012\n```\n\nMore info can be found in the [blocking README](https://github.com/Basdbruijne/autothread/blob/main/docs/README_blocking.md).\n\n## Installing\n\nYou can install autothread using:\n```\npip install autothread\n```\n\nOr by cloning the source:\n```\ngit clone https://github.com/Basdbruijne/autothread.git\ncd autothread\npip install -e .\n```\n\n## Known issues\nNone at the moment, please open a bug if you run into an issue.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "",
    "version": "0.0.10",
    "project_urls": {
        "Homepage": "https://github.com/Basdbruijne/autothread"
    },
    "split_keywords": [
        "multithreading",
        "multiprocessing",
        "decorator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4bef9927258f0224c0f20561ec15b3b86d2373cb28cd22f664ba712a393817b1",
                "md5": "775072877009aeaa90f672dc021f80a9",
                "sha256": "938aab973fdd3c85a58571d6cefc758f7f070a08a451244eedaa0f764a8807fd"
            },
            "downloads": -1,
            "filename": "autothread-0.0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "775072877009aeaa90f672dc021f80a9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14463,
            "upload_time": "2023-05-09T11:48:57",
            "upload_time_iso_8601": "2023-05-09T11:48:57.137379Z",
            "url": "https://files.pythonhosted.org/packages/4b/ef/9927258f0224c0f20561ec15b3b86d2373cb28cd22f664ba712a393817b1/autothread-0.0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-09 11:48:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Basdbruijne",
    "github_project": "autothread",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "multiprocess",
            "specs": []
        },
        {
            "name": "psutil",
            "specs": []
        },
        {
            "name": "tqdm",
            "specs": []
        },
        {
            "name": "typeguard",
            "specs": [
                [
                    ">=",
                    "3.0.2"
                ]
            ]
        },
        {
            "name": "typing",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "autothread"
}
        
Elapsed time: 0.16776s