{"id":23135184,"url":"https://github.com/mlh-fellowship/pearpy","last_synced_at":"2025-08-17T10:30:57.817Z","repository":{"id":47719330,"uuid":"390802016","full_name":"MLH-Fellowship/pearpy","owner":"MLH-Fellowship","description":"Pearpy - a Python package for writing multithreaded code and parallelizing tasks across CPU threads.","archived":false,"fork":false,"pushed_at":"2021-08-25T18:22:31.000Z","size":78,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-16T19:13:24.910Z","etag":null,"topics":["multithreading","parallelism","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pearpy","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MLH-Fellowship.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-29T17:26:29.000Z","updated_at":"2021-11-01T17:08:36.000Z","dependencies_parsed_at":"2022-08-17T15:40:51.726Z","dependency_job_id":null,"html_url":"https://github.com/MLH-Fellowship/pearpy","commit_stats":null,"previous_names":["mlh-fellowship/pear"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MLH-Fellowship%2Fpearpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MLH-Fellowship%2Fpearpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MLH-Fellowship%2Fpearpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MLH-Fellowship%2Fpearpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MLH-Fellowship","download_url":"https://codeload.github.com/MLH-Fellowship/pearpy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230113644,"owners_count":18175221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["multithreading","parallelism","python"],"created_at":"2024-12-17T12:14:27.656Z","updated_at":"2024-12-17T12:14:28.356Z","avatar_url":"https://github.com/MLH-Fellowship.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build](https://github.com/MLH-Fellowship/pod-3.1.4-team-2/actions/workflows/build.yml/badge.svg)](https://github.com/MLH-Fellowship/pod-3.1.4-team-2/actions/workflows/build.yml)\n[![PyPI version](https://img.shields.io/pypi/v/pearpy)](https://pypi.org/project/pearpy/)\n\n# Pearpy\nThe Python package for (pear)allelizing your tasks across multiple CPU threads.\n\n## Installation\nThe latest version of Pearpy can be installed with:\n```\npip install pearpy\n```\nTo stay up to date with Pearpy's releases, visit the [official page](https://pypi.org/project/pearpy/) on PyPi or take a look at our [GitHub Releases](https://github.com/MLH-Fellowship/pearpy/releases)!\n\n## Usage\n 1. Create a `Pear()` object. This will be a wrapper for all of your multithreaded processes.\n 2. Identify the functions on which you would like to paralleilze computation.\n 3. Add your tasks to the Pear. If a potential race condition is detected, target processes will be automatically locked.\n 4. Run the paraellelized processes simultaneously.\n\n## Example\n```\nfrom pearpy.pear import Pear\n\n# First function to be parallelized\ndef t1(num1, num2):\n    print('t1: ', num1 + num2)\n\n# Second function to be paralellized\ndef t2(num):\n    print('t2: ', num)\n\n# Create pear object, add threads, and run\npear = Pear()\npear.add_thread(t1, [4, 5])\npear.add_thread(t2, 4)\npear.run()\n```\n\n## Race Condition Handling\nWhen multiple threads utilize the same function, Pear will automatically generate locks for each resource. This allows developers to utilize Pear's multithreading without having to worry about inaccurate data caused by race conditions. The following example shows how race conditions are handled:\n```\nfrom pearpy.pear import Pear\n\nglobal_var = 10\n\n# This function reads from and writes to a global variable\ndef t_duplicated(num):\n    global global_var\n    print('t_duplicated: ', num + global_var)\n    global_var += 1\n\n# Pear object created with two threads accessing a shared resource\n# A race condition is detected and locks are generated\npear = Pear()\npear.add_thread(t_duplicated, 1) # This should return 11 because 1 + 10 = 11\npear.add_thread(t_duplicated, 1) # This should return 12 because global_var is incremented\npear.run()\n\n##########\n# OUTPUT #\n##########\nt_duplicated: 11\nt_duplicated: 12\n```\n\n## Benchmarks and Tests\nBenchmarks can be examined via the `make benchmark` command. This will display the threaded vs unthreaded runtimes on a set script, along with the percent improvement between the two. Here is an example of what the benchmarks should look like:\n```\n----------------------------------------------------------------------\nTHREADED BENCHMARK\n3.8507602214813232 s\n----------------------------------------------------------------------\nUNTHREADED BENCHMARK\n13.90523624420166 s\n----------------------------------------------------------------------\nImprovement:  361.1036638072611 %\n.\n----------------------------------------------------------------------\nRan 1 test in 17.757s\n\nOK\n```\nTo run tests, utilize the `make test` command. This will output the results of the functions called in the `/tests/test_pear.py` script, along with the status of the tests themselves. The console will display 'OK' if the tests are passing.\n\n## Contributing\nPear is open source and contributions from anyone are welcome. To contribute to this project, please submit issues and pull requests via GitHub. In order to successfully merge a pull request, all unit tests must be passed when run via `make test`. Thank you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlh-fellowship%2Fpearpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlh-fellowship%2Fpearpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlh-fellowship%2Fpearpy/lists"}