{ "info": { "author": "V\u00edtor Vasconcellos", "author_email": "vasconcellos.dev@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9" ], "description": "# cpu_count\n\n[![project_badge](https://img.shields.io/badge/HeavenVolkoff/cpu__count-black.svg?style=for-the-badge&logo=github \"Project Badge\")](https://github.com/HeavenVolkoff/cpu_count)\n[![version_badge](https://img.shields.io/pypi/v/cpu_count?label=version&style=for-the-badge \"Version Badge\")](https://pypi.org/project/cpu-count/)\n[![python_version](https://img.shields.io/pypi/pyversions/cpu_count?style=for-the-badge \"Python Version\")](https://pypi.org/project/cpu-count/)\n[![license_badge](https://img.shields.io/github/license/HeavenVolkoff/cpu_count.svg?style=for-the-badge \"License Badge\")](https://opensource.org/licenses/BSD-3-Clause)\n\nModified version of python's `cpu_count` that takes into account system\nconstraints to calculate the number of available CPUs\n\n## Motivation\n\nThe Python standard library offers an implementation of cpu_count that returns\nthe real number of CPUs even when they are not actually available to be used by\nthe python process (due to constraints such as CPU affinity or CPU scheduler\nconfigurations). This is the preferred behaviour for most applications. However,\nwhen the interest is the amount of CPUs available for data processing, that\napproach could be misleading. Especially when it is used behind the scenes such\nas by the `concurrent.futures.Executor` when defining its defaults.\n\nThe purpose of this module is to provide this functionality in an API equal to\nthe standard implementation. By taking into account the described constraints,\nthis implementation attempts to return the amount of usable CPUs that are\navailable. If no constraint is identified the result will be the same as the\nstandard implementation.\n\n## How to install\n\n```\npip install cpu_count\n```\n\n## How to use\n### As an external module\nThis is the standard way. Just import and call `cpu_count`\n\n```python\nfrom cpu_count import cpu_count\n\nprint(cpu_count())\n# $> 8\n```\n\n### Monkey-patch standard lib\nThis an alternative way that replaces python's standard `cpu_count` with the\none from this module (Affected internal modules are `posix`, `os` and\n`multiprocessing`). The advantage of this approach is not needing to port any\ncode, just import and call `setup_monkey_patch` ate the begin of your\napplication and everything will just work\u2122.\n\n_Note: This will also have implications in the behaviour of standard libraries\nthat use this function_\n\n```python\nimport os\nfrom cpu_count.monkey_patch import setup_monkey_patch\n\nprint(os.cpu_count())\n# $> 12\n\nsetup_monkey_patch()\n\nprint(os.cpu_count())\n# $> 8\n```\n\n#### Limitation\nThis approach has one limitation: it can't replace previous code that\nimported the standard implementation using `from os import cpu_count`.\n\n```python\nfrom os import cpu_count\nfrom cpu_count.monkey_patch import setup_monkey_patch\n\nprint(cpu_count())\n# $> 12\n\nsetup_monkey_patch()\n\nprint(cpu_count())\n# $> 12\n```\n\n### System wide monkey-patch\nThis approach also replaces python's standard `cpu_count`. However instead of\ncalling this module's `setup_monkey_patch` in your application code, it will be\ncalled at python startup. For this to work you need to create a file called\n`cpu_count_monkey_patch.pth` at your python's global or local site-package's\nfolder with the following content:\n\n```python\nimport cpu_count; cpu_count.monkey_patch.setup_monkey_patch()\n```\n\n_NOTE: This approach is specially useful when creating container images of\npython applications. An example of using this on a Dockerfile can be found\n[here](tests/docker/Dockerfile)_\n\n## TODO\n- [ ] Add logic for Realtime Scheduler constraint\n- [ ] Create unit tests\n\n## Contributions\nAll contributions are very welcome.\n\nCode styles is defined in the [Editorconfig](.editorconfig) file. Besides that\nI use black and isort for auto-format, their configurations are defined in the\n[Editorconfig](.editorconfig) and the [black.toml](black.toml) files\nrespectively.\n\n## License\nBSD 3-Clause \u201cNew\u201d or \u201cRevised\u201d License\n\nSee [LICENSE](./LICENSE)\n\n\n", "description_content_type": "text/markdown; charset=UTF-8", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/HeavenVolkoff/cpu_count", "keywords": "base,modules,package,bootstrap,foundation", "license": "BSD-3-Clause", "maintainer": "V\u00edtor Vasconcellos", "maintainer_email": "vasconcellos.dev@gmail.com", "name": "cpu-count", "package_url": "https://pypi.org/project/cpu-count/", "platform": "", "project_url": "https://pypi.org/project/cpu-count/", "project_urls": { "Bug Tracker": "https://github.com/HeavenVolkoff/cpu_count/issues", "Homepage": "https://github.com/HeavenVolkoff/cpu_count", "Source Code": "https://github.com/HeavenVolkoff/cpu_count" }, "release_url": "https://pypi.org/project/cpu-count/1.0.0/", "requires_dist": [ "importlib-metadata", "twine ; extra == 'dev'", "black ; extra == 'dev'", "isort ; extra == 'dev'", "venvtools ; extra == 'dev'" ], "requires_python": ">3.5", "summary": "Calculate the number of CPUs available taking into account system constraints", "version": "1.0.0", "yanked": false, "yanked_reason": null }, "last_serial": 6015717, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "ef2807eb36164b295da9f874eae54681", "sha256": "7cfc4130d0e44b4bee357b96d4479010d9a9fed68fb3e74ba8e87c549c0fab88" }, "downloads": -1, "filename": "cpu_count-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ef2807eb36164b295da9f874eae54681", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">3.5", "size": 7359, "upload_time": "2019-10-22T23:19:36", "upload_time_iso_8601": "2019-10-22T23:19:36.754342Z", "url": "https://files.pythonhosted.org/packages/b5/20/57fd25f1a9bd90a56a75fe1976d0c147d7a5167a2baf28a85ba9afa961cf/cpu_count-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "ae0a208ae80b73d0a2b5bd3b824de379", "sha256": "9edd8796a7fd14143f821acd4b4fc7f8e933fe9c064805892137ff9ff72a5f8b" }, "downloads": -1, "filename": "cpu_count-1.0.0.tar.gz", "has_sig": false, "md5_digest": "ae0a208ae80b73d0a2b5bd3b824de379", "packagetype": "sdist", "python_version": "source", "requires_python": ">3.5", "size": 6197, "upload_time": "2019-10-22T23:19:38", "upload_time_iso_8601": "2019-10-22T23:19:38.356718Z", "url": "https://files.pythonhosted.org/packages/2e/e3/dc921e26a47b7c549795e934008b9683f0bd1ddd6aa1a08fbc2825d25822/cpu_count-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.0b1": [ { "comment_text": "", "digests": { "md5": "cd6132e380639789a87cd49d0c1ac34a", "sha256": "053ae733de46cbcb74b2d2d8c6e70b7edc7df33bad916609aa4e6c8567f4e25d" }, "downloads": -1, "filename": "cpu_count-1.0.0b1-py3-none-any.whl", "has_sig": false, "md5_digest": "cd6132e380639789a87cd49d0c1ac34a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">3.5", "size": 5867, "upload_time": "2019-10-19T03:13:06", "upload_time_iso_8601": "2019-10-19T03:13:06.432624Z", "url": "https://files.pythonhosted.org/packages/e2/29/4a8968c7c1cb9abd8dcea85b7b3b4ba5e4517543b33b993b1ca3e8f35d46/cpu_count-1.0.0b1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "adfc01fc2bd00ec8b722bd8f5518a3ab", "sha256": "f477707598d4464be417645fc31c25e24ae39e3b9a90e1202dcd7874a9fbbd66" }, "downloads": -1, "filename": "cpu_count-1.0.0b1.tar.gz", "has_sig": false, "md5_digest": "adfc01fc2bd00ec8b722bd8f5518a3ab", "packagetype": "sdist", "python_version": "source", "requires_python": ">3.5", "size": 4478, "upload_time": "2019-10-19T03:13:09", "upload_time_iso_8601": "2019-10-19T03:13:09.680480Z", "url": "https://files.pythonhosted.org/packages/14/e5/9420415a2b4363c1fbdf48b351e9e60806be13ca71f86fa79904950a7c68/cpu_count-1.0.0b1.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.0b2": [ { "comment_text": "", "digests": { "md5": "160a731344cad44d25bc38b08bd2f333", "sha256": "dcc7f2c693b4fd8dfdf8c8e03742441d4c7f50caeda8eef088180e05b08bea56" }, "downloads": -1, "filename": "cpu_count-1.0.0b2-py3-none-any.whl", "has_sig": false, "md5_digest": "160a731344cad44d25bc38b08bd2f333", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">3.5", "size": 5860, "upload_time": "2019-10-19T03:15:56", "upload_time_iso_8601": "2019-10-19T03:15:56.006280Z", "url": "https://files.pythonhosted.org/packages/2d/a5/d44882c3e1b48ead37eeb45b089a95e30da6e4514e50623ceb809e966e23/cpu_count-1.0.0b2-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "8c6ba6700a262fe6519fb7515bdc51a2", "sha256": "23e294cae5796b42a79853dc9461b447bd79290ac011c61e2fd6e810c2b5a931" }, "downloads": -1, "filename": "cpu_count-1.0.0b2.tar.gz", "has_sig": false, "md5_digest": "8c6ba6700a262fe6519fb7515bdc51a2", "packagetype": "sdist", "python_version": "source", "requires_python": ">3.5", "size": 4471, "upload_time": "2019-10-19T03:15:58", "upload_time_iso_8601": "2019-10-19T03:15:58.838169Z", "url": "https://files.pythonhosted.org/packages/1c/7c/8fcbebff8afd03e1ed054655f785f03ed111c3ae094efc6c0b36184012d3/cpu_count-1.0.0b2.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.0b3": [ { "comment_text": "", "digests": { "md5": "4eb6faa9c2cd0006cff46814ab3e6387", "sha256": "4647387b2d84ff4d37905ce0f4dad56d7a8b236d6490e7af92608435f3fd197d" }, "downloads": -1, "filename": "cpu_count-1.0.0b3-py3-none-any.whl", "has_sig": false, "md5_digest": "4eb6faa9c2cd0006cff46814ab3e6387", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">3.5", "size": 6104, "upload_time": "2019-10-19T18:44:13", "upload_time_iso_8601": "2019-10-19T18:44:13.576140Z", "url": "https://files.pythonhosted.org/packages/7b/6a/bc8aeaccf7864272063a334589d42910a18a941d398297264868f6e39351/cpu_count-1.0.0b3-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "6e1a9a7965333229a86bc93c52e06c3e", "sha256": "0fe3c80be55ac6a9bc75d2898c65034d9510ffbe248b8beae7700d538f537bee" }, "downloads": -1, "filename": "cpu_count-1.0.0b3.tar.gz", "has_sig": false, "md5_digest": "6e1a9a7965333229a86bc93c52e06c3e", "packagetype": "sdist", "python_version": "source", "requires_python": ">3.5", "size": 4713, "upload_time": "2019-10-19T18:44:15", "upload_time_iso_8601": "2019-10-19T18:44:15.237735Z", "url": "https://files.pythonhosted.org/packages/51/9d/2d7b5ca1dce550806595db56bad381c765ccbb5ac9cd135c3a96bb8cd7cb/cpu_count-1.0.0b3.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ef2807eb36164b295da9f874eae54681", "sha256": "7cfc4130d0e44b4bee357b96d4479010d9a9fed68fb3e74ba8e87c549c0fab88" }, "downloads": -1, "filename": "cpu_count-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ef2807eb36164b295da9f874eae54681", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">3.5", "size": 7359, "upload_time": "2019-10-22T23:19:36", "upload_time_iso_8601": "2019-10-22T23:19:36.754342Z", "url": "https://files.pythonhosted.org/packages/b5/20/57fd25f1a9bd90a56a75fe1976d0c147d7a5167a2baf28a85ba9afa961cf/cpu_count-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "ae0a208ae80b73d0a2b5bd3b824de379", "sha256": "9edd8796a7fd14143f821acd4b4fc7f8e933fe9c064805892137ff9ff72a5f8b" }, "downloads": -1, "filename": "cpu_count-1.0.0.tar.gz", "has_sig": false, "md5_digest": "ae0a208ae80b73d0a2b5bd3b824de379", "packagetype": "sdist", "python_version": "source", "requires_python": ">3.5", "size": 6197, "upload_time": "2019-10-22T23:19:38", "upload_time_iso_8601": "2019-10-22T23:19:38.356718Z", "url": "https://files.pythonhosted.org/packages/2e/e3/dc921e26a47b7c549795e934008b9683f0bd1ddd6aa1a08fbc2825d25822/cpu_count-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }