{ "info": { "author": "Jason Zi Feng Lei", "author_email": "TokenChingy@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Pytasking\n\nA simple library for Python 3.5+ that provides an easy interface for multitasking.\n\n## Table of Contents\n\n- [Pytasking](#pytasking)\n - [Table of Contents](#table-of-contents)\n - [Dependencies](#dependencies)\n - [Installation](#installation)\n - [Source](#source)\n - [PyPi](#pypi)\n - [Usage](#usage)\n - [API](#api)\n - [`class pytasking.Manager()`](#class-pytaskingmanager)\n - [`add_task(task, *args, **kwargs)`](#addtasktask-args-kwargs)\n - [`delete_task(t_id)`](#deletetasktid)\n - [`get_task(t_id)`](#gettasktid)\n - [`get_tasks()`](#gettasks)\n - [`add_proc(proc, *args, **kwargs)`](#addprocproc-args-kwargs)\n - [`delete_proc(p_id)`](#deleteprocpid)\n - [`get_proc(p_id)`](#getprocpid)\n - [`get_procs()`](#getprocs)\n - [`start()`](#start)\n - [Known Issues](#known-issues)\n - [Recursive spawning](#recursive-spawning)\n - [Pipe/Queue corruption](#pipequeue-corruption)\n - [Changelog](#changelog)\n - [1.2](#12)\n - [Breaking Changes](#breaking-changes)\n - [1.1.0](#110)\n - [1.0.0](#100)\n\n\n## Dependencies\n\n- Python 3.5+\n\n*There are no external module dependencies outside of the standard library however, if you'd like to take advantage of `uvloop`, you can install that and the `pytasking` library will use it automatically (Only available on Linux/MacOS).*\n\n## Installation\n\n### Source\n\n- Include the directory `pytasking` in your project root directory.\n- If on Linux/MacOS; run `python -m pip install -r requirements.txt`.\n\n### PyPi\n\n- Run `pip install pytasking`.\n\n## Usage\n\nA basic python example:\n\n```python\n#!/usr/bin/env python\n\nimport pytasking\nimport time\n\n\ndef hello(hello_queue):\n while True:\n hello_queue.put_nowait(\"Hello World!\")\n pytasking.sleep(1.5, sync=True)\n\n\nasync def ping():\n while True:\n try:\n print(\"Ping!\")\n await pytasking.sleep(1.0)\n print(\"Pong!\")\n except pytasking.asyncio.CancelledError:\n print(\"Pang!\")\n break\n\n\nasync def main(task_manager):\n hellos = 0\n hello_queue = pytasking.multiprocessing.Queue()\n hello_proc = task_manager.add_proc(hello, hello_queue)\n\n while True:\n try:\n if hellos == 5:\n task_manager.delete_proc(hello_proc)\n\n if hello_queue.qsize() > 0:\n try:\n print(hello_queue.get_nowait())\n hellos += 1\n except:\n pass\n\n ping_task = task_manager.add_task(ping)\n await pytasking.sleep(0.5)\n task_manager.delete_task(ping_task)\n except pytasking.asyncio.CancelledError:\n break\n\n\nif __name__ == \"__main__\":\n task_manager = pytasking.Manager()\n task_manager.add_task(main, task_manager)\n\n try:\n task_manager.start()\n except KeyboardInterrupt:\n pass\n except:\n raise\n```\n\n## API\n\n### `class pytasking.Manager()`\n\nInstances of the `Manager` class provide an asynchronous event loop to the program. Currently pytasking **only supports 1 asynchronous event loop** at any given time.\n\nAsynchronous tasks and parallel processes are spawned and managed by the `Manager` instance.\n\n#### `add_task(task, *args, **kwargs)`\n\nCreate an asynchronous task from a function definition. Pass arguments and keyword arguments as you would normally. This function returns an id from the has of the task. You can use the id to retrieve and delete the task. Make sure you define your function with the following template:\n\n```python\nasync def asynchronous_task_definition(): # Define any arguments or keyword arguments as you normally would.\n # Do whatever you need to do here as you normally would.\n\n # If you want this task to run indefinitely, do this:\n while True:\n try:\n # Do something forever.\n await pytasking.sleep(1.0)\n except pytasking.asyncio.CancelledError: # This one is important.\n # Normally you catch the cancel event and do something with it, but in this case, use it to break the loop and allow the task to close the task.\n break\n except:\n raise\n```\n\nTasks will start immediately and you may add a task anytime.\n\n#### `delete_task(t_id)`\n\nGiven a task id, you can call to delete a task. This method calls the `cancel()` method of the coroutine, it will give the coroutine the chance to cleanup and even deny the request if caught and handled in the `pytasking.CancelledError`.\n\n#### `get_task(t_id)`\n\nIf you want to retrieve the underlying coroutine, you can use this method and provide the task id to get it.\n\n#### `get_tasks()`\n\nThis will return all the task ids as a list, you can use this method in conjunction with `get_task(t_id)`.\n\n#### `add_proc(proc, *args, **kwargs)`\n\nCreate a parallel process from a function definition. Pass arguments and keyword arguments as you would normally. This function returns an id from the has of the process. You can use the id to retrieve and delete the process. Do note, by default the process runs sequentially. Try to follow this template:\n\n```python\ndef parallel_process(): # Define any arguments or keyword arguments as you normally would.\n # Do whatever you need to do here as you normally would.\n\n # If you want this task to run indefinitely, do this:\n while True:\n try:\n # Do something forever.\n pytasking.sleep(1.0, sync=True)\n except:\n raise\n```\n\n#### `delete_proc(p_id)`\n\nGiven a process id, you can call to delete a process. This method calls `terminate()` and `join()` to attempt to cleanly close the process. Closing the process while it is accessing a Pipe or Queue, may corrupt the resource.\n\n#### `get_proc(p_id)`\n\nIf you want to retrieve the underlying process, you can use this method and provide the process id to get it.\n\n#### `get_procs()`\n\nThis will return all the process ids as a list, you can use this method in conjunction with `get_process(p_id)`.\n\n#### `start()`\n\nThis begins the `Manager` instance and starts all added tasks and processes.\n\n## Known Issues\n\n### Recursive spawning\n\nThere maybe situations where you cannot spawn a task in a task, process in a process, task in a process, or a process in a task. I'll need to investigate further.\n\n### Pipe/Queue corruption\n\nIf you decide to delete a process be wary, if the process was in the middle of accessing a Queue or Pipe, that Queue or Pipe will be liable to corruption and will not be usable again.\n\n## Changelog\n\n### 1.2\n\n- Changing naming convention, moving toward 1.x convention.\n\n#### Breaking Changes\n\n- All wrapped exceptions and data structures from the `asyncio` and `multiprocessing` modules have now been namespaced into pytasking. For example; `pytasking.CancelledError` is now `pytasking.asyncio.CancelledError`. This change is so that it is more explicit and natural.\n\n### 1.1.0\n\n- Improved documentation.\n- Implemented additional helper methods for the Manager class \u00e2\u20ac\u201c see the documentation for details.\n\n### 1.0.0\n\n- This is the initial release of pytasking.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/TokenChingy/pytasking", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "pytasking", "package_url": "https://pypi.org/project/pytasking/", "platform": "", "project_url": "https://pypi.org/project/pytasking/", "project_urls": { "Homepage": "https://github.com/TokenChingy/pytasking" }, "release_url": "https://pypi.org/project/pytasking/1.2/", "requires_dist": null, "requires_python": ">=3.5", "summary": "A multitasking library for Python 3.5+", "version": "1.2", "yanked": false, "yanked_reason": null }, "last_serial": 6247145, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "d2df87b915a13061e9da640c90ce02f9", "sha256": "206d1ba3136f801d30baf7ea1cca983d43c4d15ed3581b6ee09b806d25f1134a" }, "downloads": -1, "filename": "pytasking-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d2df87b915a13061e9da640c90ce02f9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 4377, "upload_time": "2019-10-21T12:13:41", "upload_time_iso_8601": "2019-10-21T12:13:41.900248Z", "url": "https://files.pythonhosted.org/packages/11/c9/92f157ce098b5388665eafdcb8e2aff0afda1c8bf0ff68d75981b3cff8a8/pytasking-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "0c4565343dd23bac503dc5b4c3c29334", "sha256": "cca9ad527704718675682a143d19cd8157d0672148c22d1969fa596f29b0e2c0" }, "downloads": -1, "filename": "pytasking-1.0.0.tar.gz", "has_sig": false, "md5_digest": "0c4565343dd23bac503dc5b4c3c29334", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 3187, "upload_time": "2019-10-21T12:13:43", "upload_time_iso_8601": "2019-10-21T12:13:43.767251Z", "url": "https://files.pythonhosted.org/packages/bd/e9/55305b4a102e02778e7179eae549a849902e6e26e33499dbfae7741b4830/pytasking-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "a38fed89787fc81f295062cb781de8d1", "sha256": "167894c14c5489b7fe37a565db2211d55e4fc000a8a0c7d2e2040c8fe03080d7" }, "downloads": -1, "filename": "pytasking-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "a38fed89787fc81f295062cb781de8d1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 5514, "upload_time": "2019-12-03T02:56:01", "upload_time_iso_8601": "2019-12-03T02:56:01.464762Z", "url": "https://files.pythonhosted.org/packages/d0/0c/bab6616d1d59336805e9b9170b5bdfdcd1042e80f17b80d747d24483ba71/pytasking-1.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "96997373ddd0bf00377fbaed6a766b7d", "sha256": "eb93d95995db32f824ca8426fc175e46c92e6feb5fcd4e3310be377b0a0bbd6b" }, "downloads": -1, "filename": "pytasking-1.1.0.tar.gz", "has_sig": false, "md5_digest": "96997373ddd0bf00377fbaed6a766b7d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 4700, "upload_time": "2019-12-03T02:56:04", "upload_time_iso_8601": "2019-12-03T02:56:04.064647Z", "url": "https://files.pythonhosted.org/packages/1e/ed/433408faa80e232aa463bd6dd6d6613107bc7267cb0c3143e2e66ae85702/pytasking-1.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "1.2": [ { "comment_text": "", "digests": { "md5": "77540e4222870b28bc5b4ab75e67672c", "sha256": "7de35e3780eea6075742a736db168ec1b4f6677d77fa51e6e5f19f74ba21cfaf" }, "downloads": -1, "filename": "pytasking-1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "77540e4222870b28bc5b4ab75e67672c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 5701, "upload_time": "2019-12-05T12:25:17", "upload_time_iso_8601": "2019-12-05T12:25:17.765178Z", "url": "https://files.pythonhosted.org/packages/fe/46/d643ac10a79a615cde08834c08397c110c486207e73d68fbc36f54df9340/pytasking-1.2-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "fc753907960d9a43eedb06c797cbbde2", "sha256": "45b42edd805af651151256eea0b15937a6003f36d7b256da5614a004c862e2d2" }, "downloads": -1, "filename": "pytasking-1.2.tar.gz", "has_sig": false, "md5_digest": "fc753907960d9a43eedb06c797cbbde2", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5844, "upload_time": "2019-12-05T12:25:21", "upload_time_iso_8601": "2019-12-05T12:25:21.317210Z", "url": "https://files.pythonhosted.org/packages/e0/96/cc48dd61078331d2a60cf8251687bb456bf9422325d972392bc716ffdab6/pytasking-1.2.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "77540e4222870b28bc5b4ab75e67672c", "sha256": "7de35e3780eea6075742a736db168ec1b4f6677d77fa51e6e5f19f74ba21cfaf" }, "downloads": -1, "filename": "pytasking-1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "77540e4222870b28bc5b4ab75e67672c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 5701, "upload_time": "2019-12-05T12:25:17", "upload_time_iso_8601": "2019-12-05T12:25:17.765178Z", "url": "https://files.pythonhosted.org/packages/fe/46/d643ac10a79a615cde08834c08397c110c486207e73d68fbc36f54df9340/pytasking-1.2-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "fc753907960d9a43eedb06c797cbbde2", "sha256": "45b42edd805af651151256eea0b15937a6003f36d7b256da5614a004c862e2d2" }, "downloads": -1, "filename": "pytasking-1.2.tar.gz", "has_sig": false, "md5_digest": "fc753907960d9a43eedb06c797cbbde2", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5844, "upload_time": "2019-12-05T12:25:21", "upload_time_iso_8601": "2019-12-05T12:25:21.317210Z", "url": "https://files.pythonhosted.org/packages/e0/96/cc48dd61078331d2a60cf8251687bb456bf9422325d972392bc716ffdab6/pytasking-1.2.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }