{ "info": { "author": "Georgi Valkov", "author_email": "georgi.t.valkov@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries" ], "description": "Commandpool\n===========\n\n.. class:: no-web no-pdf\n\n|pypi| |build| |license|\n\nUtility classes and functions for running subprocess commands in parallel:\n\n.. code-block:: python\n\n >>> from random import randrange\n >>> from commandpool import run\n\n >>> commands = ['sleep %s' % randrange(5) for _ in range(100)]\n\n >>> for proc, cmd in run(commands):\n ... print(proc.returncode, proc, cmd, sep=', ')\n 0, , sleep 1\n 0, , sleep 2\n 0, , sleep 2\n 0, , sleep 3\n 0, , sleep 3\n 0, , sleep 4\n\nOne way to look at the functionality provided by this library is like a\n`subprocess`_ equivalent of:\n\n.. code-block:: shell\n\n echo $commands | xargs -P $concurrency sh -c\n\nThis library works by periodically checking if started processes have finished\nand then starting new ones in their place.\n\nInstallation\n------------\n\nThe latest stable version of commandpool can be installed from pypi:\n\n.. code-block:: bash\n\n $ pip install commandpool\n\n\nUsage\n-----\n\nFunctional\n~~~~~~~~~~\n\n.. code-block:: python\n\n from commandpool import run\n\n # Run at most 5 commands at a time.\n run(commands, concurrency=5)\n\n # Start all commands at the same time (this is the default).\n run(commands, concurrency=None)\n\n # The duration between 'ticks' is configurable.\n run(commands, sleep_seconds=0.1)\n\n # Processing commands as they are finished.\n for proc, cmd in run(commands):\n assert isinstance(proc, subprocess.Popen)\n\n # The way commands are started is configurable through `start_command`.\n from subprocess import Popen, PIPE\n\n commands = {i: ('echo', i*i) for i in range(5, 10)}\n start_command = lambda num: Popen(commands[num], stdout=PIPE)\n\n for proc, cmd in run(commands, start_command=start_command):\n print(proc.stdout, cmd, commands[cmd])\n # b'25', 5, ('echo', 25)\n # b'36', 6, ('echo', 36)\n # ...\n\n\nSubclassing\n~~~~~~~~~~~\n\n.. code-block:: python\n\n from commandpool import ConcurrentCommandRunner\n\n class MyCommandRunner(ConcurrentCommandRunner):\n def start_command(self, cmd):\n ...\n\n def command_finished(self, proc, cmd):\n ...\n\n runner = MyCommandRunner(commands, sleep_interval=1.0)\n runner.run()\n\n\nTodo\n----\n\n- Add tests.\n\n- Complete documentation.\n\n\nAlternatives\n------------\n\n``ConcurrentCommandRunner`` can be implemented in a few lines with the help of\n`concurrent.futures`_, assuming that spawning a thread per command is\nacceptable. This also has the added benefit of yielding as soon as a command\n(wrapped in a future) is complete, instead of at ``sleep_seconds`` intervals, as\nis the case with ``ConcurrentCommandRunner``.\n\n.. code-block:: python\n\n from concurrent.futures import ThreadPoolExecutor, as_completed\n from subprocess import run\n\n with ThreadPoolExecutor(max_workers=10) as pool:\n futures = {pool.submit(run, cmd): cmd for cmd in commands}\n for res in as_completed(futures):\n print(futures[res], res.returncode)\n\n\nLicense\n-------\n\nReleased under the terms of the `Revised BSD License`_.\n\n\n.. |pypi| image:: https://img.shields.io/pypi/v/commandpool.svg?style=flat-square&label=latest%20stable%20version\n :target: https://pypi.python.org/pypi/commandpool\n :alt: Latest version released on PyPi\n\n.. |license| image:: https://img.shields.io/pypi/l/commandpool.svg?style=flat-square&label=license\n :target: https://pypi.python.org/pypi/commandpool\n :alt: BSD 3-Clause\n\n.. |build| image:: https://img.shields.io/travis/gvalkov/python-commandpool/master.svg?style=flat-square&label=build\n :target: http://travis-ci.org/gvalkov/python-commandpool\n :alt: Build status\n\n.. _`Revised BSD License`: https://raw.github.com/gvalkov/python-commandpool/master/LICENSE\n.. _subprocess: https://docs.python.org/3/library/subprocess.html\n.. _`concurrent.futures`: https://docs.python.org/3/library/concurrent.futures.html\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/gvalkov/python-commandpool", "keywords": "subprocess pool", "license": "Revised BSD License", "maintainer": "", "maintainer_email": "", "name": "commandpool", "package_url": "https://pypi.org/project/commandpool/", "platform": "", "project_url": "https://pypi.org/project/commandpool/", "project_urls": { "Homepage": "https://github.com/gvalkov/python-commandpool" }, "release_url": "https://pypi.org/project/commandpool/0.0.0/", "requires_dist": null, "requires_python": "", "summary": "Functions for running many subprocesses in parallel", "version": "0.0.0" }, "last_serial": 3254971, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "f76c17f7c78a0adccfdb0b3bc8ebf61a", "sha256": "9c8d4518b3db7a6c851e23ab68aaa9e561f6d1b5bf901510e96bce6f46bbc7c0" }, "downloads": -1, "filename": "commandpool-0.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f76c17f7c78a0adccfdb0b3bc8ebf61a", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 7211, "upload_time": "2017-10-16T23:10:10", "url": "https://files.pythonhosted.org/packages/63/26/ab25501918b6970fd0ece1d10da1db31570948ea772b15cdde7456952aee/commandpool-0.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ecc59b8829e82e9897b499c68b0cfd0d", "sha256": "090bbf7418e75e2da04e15ca3cd65bce3e49944c0f50a140659140713e14e92a" }, "downloads": -1, "filename": "commandpool-0.0.0.tar.gz", "has_sig": false, "md5_digest": "ecc59b8829e82e9897b499c68b0cfd0d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4771, "upload_time": "2017-10-16T23:10:09", "url": "https://files.pythonhosted.org/packages/87/59/2a5dc2e98124586a72239d8a0ad0d50a339363bff287e502a2ea80c78aa3/commandpool-0.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f76c17f7c78a0adccfdb0b3bc8ebf61a", "sha256": "9c8d4518b3db7a6c851e23ab68aaa9e561f6d1b5bf901510e96bce6f46bbc7c0" }, "downloads": -1, "filename": "commandpool-0.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f76c17f7c78a0adccfdb0b3bc8ebf61a", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 7211, "upload_time": "2017-10-16T23:10:10", "url": "https://files.pythonhosted.org/packages/63/26/ab25501918b6970fd0ece1d10da1db31570948ea772b15cdde7456952aee/commandpool-0.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ecc59b8829e82e9897b499c68b0cfd0d", "sha256": "090bbf7418e75e2da04e15ca3cd65bce3e49944c0f50a140659140713e14e92a" }, "downloads": -1, "filename": "commandpool-0.0.0.tar.gz", "has_sig": false, "md5_digest": "ecc59b8829e82e9897b499c68b0cfd0d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4771, "upload_time": "2017-10-16T23:10:09", "url": "https://files.pythonhosted.org/packages/87/59/2a5dc2e98124586a72239d8a0ad0d50a339363bff287e502a2ea80c78aa3/commandpool-0.0.0.tar.gz" } ] }