MultiTasking: Non-blocking Python methods using decorators
==========================================================
.. image:: https://img.shields.io/badge/python-2.7,%203.5+-blue.svg?style=flat
:target: https://pypi.python.org/pypi/multitasking
:alt: Python version
.. image:: https://img.shields.io/travis/ranaroussi/multitasking/main.svg?
:target: https://travis-ci.org/ranaroussi/multitasking
:alt: Travis-CI build status
.. image:: https://img.shields.io/pypi/v/multitasking.svg?maxAge=60
:target: https://pypi.python.org/pypi/multitasking
:alt: PyPi version
.. image:: https://img.shields.io/pypi/status/multitasking.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/multitasking
:alt: PyPi status
.. image:: https://img.shields.io/pypi/dm/multitasking.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/multitasking
:alt: PyPi downloads
.. image:: https://www.codefactor.io/repository/github/ranaroussi/multitasking/badge
:target: https://www.codefactor.io/repository/github/ranaroussi/multitasking
:alt: CodeFactor
.. image:: https://img.shields.io/github/stars/ranaroussi/multitasking.svg?style=social&label=Star&maxAge=60
:target: https://github.com/ranaroussi/multitasking
:alt: Star this repo
.. image:: https://img.shields.io/twitter/follow/aroussi.svg?style=social&label=Follow%20Me&maxAge=60
:target: https://twitter.com/aroussi
:alt: Follow me on twitter
\
**MultiTasking** is a tiny Python library lets you convert your Python methods into asynchronous,
non-blocking methods simply by using a decorator.
Example
--------------------
.. code:: python
# example.py
import multitasking
import time
import random
import signal
# kill all tasks on ctrl-c
signal.signal(signal.SIGINT, multitasking.killall)
# or, wait for task to finish on ctrl-c:
# signal.signal(signal.SIGINT, multitasking.wait_for_tasks)
@multitasking.task # <== this is all it takes :-)
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)
The output would look something like this:
.. code:: bash
$ python example.py
Hello 1 (sleeping for 0.5s)
Hello 2 (sleeping for 1.0s)
Hello 3 (sleeping for 5.0s)
Hello 4 (sleeping for 0.5s)
Hello 5 (sleeping for 2.5s)
Hello 6 (sleeping for 3.0s)
Hello 7 (sleeping for 0.5s)
Hello 8 (sleeping for 4.0s)
Hello 9 (sleeping for 3.0s)
Hello 10 (sleeping for 1.0s)
Goodbye 1 (after for 0.5s)
Goodbye 4 (after for 0.5s)
Goodbye 7 (after for 0.5s)
Goodbye 2 (after for 1.0s)
Goodbye 10 (after for 1.0s)
Goodbye 5 (after for 2.5s)
Goodbye 6 (after for 3.0s)
Goodbye 9 (after for 3.0s)
Goodbye 8 (after for 4.0s)
Goodbye 3 (after for 5.0s)
Settings
========
The default maximum threads is equal to the # of CPU Cores.
**This is just a rule of thumb!** The ``Thread`` module isn't actually using more than one core at a time.
You can change the default maximum number of threads using:
.. code:: python
import multitasking
multitasking.set_max_threads(10)
...or, if you want to set the maximum number of threads based on the number of CPU Cores, you can:
.. code:: python
import multitasking
multitasking.set_max_threads(multitasking.config["CPU_CORES"] * 5)
For applications that doesn't require access to shared resources,
you can set ``MultiTasking`` to use ``multiprocessing.Process()``
instead of the ``threading.Thread()``, thus avoiding some of the
`GIL constraints <https://jeffknupp.com/blog/2013/06/30/pythons-hardest-problem-revisited/>`_.
.. code:: python
import multitasking
multitasking.set_engine("process") # "process" or "thread"
Installation
============
Install multitasking using ``pip``:
.. code:: bash
$ pip install multitasking --upgrade --no-cache-dir
Install multitasking using ``conda``:
.. code:: bash
$ conda install -c ranaroussi multitasking
Legal Stuff
===========
**MultiTasking** is distributed under the **Apache Software License**. See the `LICENSE.txt <./LICENSE.txt>`_ file in the release for details.
P.S.
------------
Please drop me an note with any feedback you have.
**Ran Aroussi**
Raw data
{
"_id": null,
"home_page": "https://github.com/ranaroussi/multitasking",
"name": "multitasking",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "multitasking multitask threading async",
"author": "Ran Aroussi",
"author_email": "ran@aroussi.com",
"download_url": "https://files.pythonhosted.org/packages/6f/75/345e196762fc51fb5b4e9504631972b1271a0cb2ba1ce2afe5b185c95b64/multitasking-0.0.11.tar.gz",
"platform": "any",
"description": "MultiTasking: Non-blocking Python methods using decorators\n==========================================================\n\n.. image:: https://img.shields.io/badge/python-2.7,%203.5+-blue.svg?style=flat\n :target: https://pypi.python.org/pypi/multitasking\n :alt: Python version\n\n.. image:: https://img.shields.io/travis/ranaroussi/multitasking/main.svg?\n :target: https://travis-ci.org/ranaroussi/multitasking\n :alt: Travis-CI build status\n\n.. image:: https://img.shields.io/pypi/v/multitasking.svg?maxAge=60\n :target: https://pypi.python.org/pypi/multitasking\n :alt: PyPi version\n\n.. image:: https://img.shields.io/pypi/status/multitasking.svg?maxAge=2592000\n :target: https://pypi.python.org/pypi/multitasking\n :alt: PyPi status\n\n.. image:: https://img.shields.io/pypi/dm/multitasking.svg?maxAge=2592000\n :target: https://pypi.python.org/pypi/multitasking\n :alt: PyPi downloads\n\n.. image:: https://www.codefactor.io/repository/github/ranaroussi/multitasking/badge\n :target: https://www.codefactor.io/repository/github/ranaroussi/multitasking\n :alt: CodeFactor\n\n.. image:: https://img.shields.io/github/stars/ranaroussi/multitasking.svg?style=social&label=Star&maxAge=60\n :target: https://github.com/ranaroussi/multitasking\n :alt: Star this repo\n\n.. image:: https://img.shields.io/twitter/follow/aroussi.svg?style=social&label=Follow%20Me&maxAge=60\n :target: https://twitter.com/aroussi\n :alt: Follow me on twitter\n\n\\\n\n**MultiTasking** is a tiny Python library lets you convert your Python methods into asynchronous,\nnon-blocking methods simply by using a decorator.\n\nExample\n--------------------\n.. code:: python\n\n # example.py\n import multitasking\n import time\n import random\n import signal\n\n # kill all tasks on ctrl-c\n signal.signal(signal.SIGINT, multitasking.killall)\n\n # or, wait for task to finish on ctrl-c:\n # signal.signal(signal.SIGINT, multitasking.wait_for_tasks)\n\n @multitasking.task # <== this is all it takes :-)\n def hello(count):\n sleep = random.randint(1,10)/2\n print(\"Hello %s (sleeping for %ss)\" % (count, sleep))\n time.sleep(sleep)\n print(\"Goodbye %s (after for %ss)\" % (count, sleep))\n\n if __name__ == \"__main__\":\n for i in range(0, 10):\n hello(i+1)\n\n\nThe output would look something like this:\n\n.. code:: bash\n\n $ python example.py\n\n Hello 1 (sleeping for 0.5s)\n Hello 2 (sleeping for 1.0s)\n Hello 3 (sleeping for 5.0s)\n Hello 4 (sleeping for 0.5s)\n Hello 5 (sleeping for 2.5s)\n Hello 6 (sleeping for 3.0s)\n Hello 7 (sleeping for 0.5s)\n Hello 8 (sleeping for 4.0s)\n Hello 9 (sleeping for 3.0s)\n Hello 10 (sleeping for 1.0s)\n Goodbye 1 (after for 0.5s)\n Goodbye 4 (after for 0.5s)\n Goodbye 7 (after for 0.5s)\n Goodbye 2 (after for 1.0s)\n Goodbye 10 (after for 1.0s)\n Goodbye 5 (after for 2.5s)\n Goodbye 6 (after for 3.0s)\n Goodbye 9 (after for 3.0s)\n Goodbye 8 (after for 4.0s)\n Goodbye 3 (after for 5.0s)\n\n\nSettings\n========\n\nThe default maximum threads is equal to the # of CPU Cores.\n**This is just a rule of thumb!** The ``Thread`` module isn't actually using more than one core at a time.\n\nYou can change the default maximum number of threads using:\n\n.. code:: python\n\n import multitasking\n multitasking.set_max_threads(10)\n\n...or, if you want to set the maximum number of threads based on the number of CPU Cores, you can:\n\n.. code:: python\n\n import multitasking\n multitasking.set_max_threads(multitasking.config[\"CPU_CORES\"] * 5)\n\nFor applications that doesn't require access to shared resources,\nyou can set ``MultiTasking`` to use ``multiprocessing.Process()``\ninstead of the ``threading.Thread()``, thus avoiding some of the\n`GIL constraints <https://jeffknupp.com/blog/2013/06/30/pythons-hardest-problem-revisited/>`_.\n\n.. code:: python\n\n import multitasking\n multitasking.set_engine(\"process\") # \"process\" or \"thread\"\n\n\nInstallation\n============\n\nInstall multitasking using ``pip``:\n\n.. code:: bash\n\n $ pip install multitasking --upgrade --no-cache-dir\n\n\nInstall multitasking using ``conda``:\n\n.. code:: bash\n\n $ conda install -c ranaroussi multitasking\n\n\nLegal Stuff\n===========\n\n**MultiTasking** is distributed under the **Apache Software License**. See the `LICENSE.txt <./LICENSE.txt>`_ file in the release for details.\n\n\nP.S.\n------------\n\nPlease drop me an note with any feedback you have.\n\n**Ran Aroussi**\n\n\n",
"bugtrack_url": null,
"license": "Apache",
"summary": "Non-blocking Python methods using decorators",
"version": "0.0.11",
"split_keywords": [
"multitasking",
"multitask",
"threading",
"async"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "5eb106275258cf36f020c0632c67f742",
"sha256": "1e5b37a5f8fc1e6cfaafd1a82b6b1cc6d2ed20037d3b89c25a84f499bd7b3dd4"
},
"downloads": -1,
"filename": "multitasking-0.0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5eb106275258cf36f020c0632c67f742",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8533,
"upload_time": "2022-06-28T08:40:44",
"upload_time_iso_8601": "2022-06-28T08:40:44.524018Z",
"url": "https://files.pythonhosted.org/packages/3e/8a/bb3160e76e844db9e69a413f055818969c8acade64e1a9ac5ce9dfdcf6c1/multitasking-0.0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "1c3580747da6181a8bce61d22d315df2",
"sha256": "4d6bc3cc65f9b2dca72fb5a787850a88dae8f620c2b36ae9b55248e51bcd6026"
},
"downloads": -1,
"filename": "multitasking-0.0.11.tar.gz",
"has_sig": false,
"md5_digest": "1c3580747da6181a8bce61d22d315df2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8150,
"upload_time": "2022-06-28T08:40:46",
"upload_time_iso_8601": "2022-06-28T08:40:46.278736Z",
"url": "https://files.pythonhosted.org/packages/6f/75/345e196762fc51fb5b4e9504631972b1271a0cb2ba1ce2afe5b185c95b64/multitasking-0.0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-06-28 08:40:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "ranaroussi",
"github_project": "multitasking",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "multitasking"
}