{"id":16652887,"url":"https://github.com/zerointensity/rethread","last_synced_at":"2025-06-27T22:06:40.210Z","repository":{"id":107060767,"uuid":"440204378","full_name":"ZeroIntensity/rethread","owner":"ZeroIntensity","description":"Easy multithreading for Python","archived":false,"fork":false,"pushed_at":"2022-03-10T14:42:32.000Z","size":5,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-22T23:12:20.698Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/rethread","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZeroIntensity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-20T14:45:12.000Z","updated_at":"2023-03-31T08:42:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"c470e19e-db6c-43c8-9034-013778b81fa6","html_url":"https://github.com/ZeroIntensity/rethread","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ZeroIntensity/rethread","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroIntensity%2Frethread","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroIntensity%2Frethread/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroIntensity%2Frethread/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroIntensity%2Frethread/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZeroIntensity","download_url":"https://codeload.github.com/ZeroIntensity/rethread/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroIntensity%2Frethread/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262341617,"owners_count":23296069,"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":[],"created_at":"2024-10-12T09:30:19.138Z","updated_at":"2025-06-27T22:06:40.202Z","avatar_url":"https://github.com/ZeroIntensity.png","language":"Python","readme":"# ReThread\r\n\r\n## Minimalistic Python Library for Easy Multithreading\r\n\r\n### Installation\r\n\r\n#### Linux/Mac\r\n\r\n```\r\npython3 -m pip install -U rethread\r\n```\r\n\r\n#### Windows\r\n\r\n```\r\npy -3 -m pip install -U rethread\r\n```\r\n\r\n### Example\r\n\r\n```py\r\nimport rethread\r\nimport time\r\n\r\n@rethread.auto\r\ndef my_long_function():\r\n    time.sleep(10)\r\n\r\n    return 'a'\r\n\r\ndef some_other_function():\r\n    for i in range(3):\r\n        time.sleep(1)\r\n        print(i)\r\n\r\ndef another_function(t: rethread.RunningThread):\r\n    time.sleep(10)\r\n\r\n    if t.done:\r\n        print('thread is finished!')\r\n\r\n\r\nwith my_long_function() as t:\r\n    some_other_function()\r\n    another_function(t)\r\n\r\nprint(thread.value)\r\n```\r\n\r\n## Usage\r\n\r\nTo create a thread, you can use the `rethread.thread` function, like so:\r\n\r\n```py\r\nimport rethread\r\n\r\ndef long_function():\r\n    ...\r\n\r\nthread: rethread.RunningThread = rethread.thread(long_function)\r\n```\r\n\r\nIf you would like to pass in parameters, simply pass them in to the `*args` and `**kwargs` of the `rethread.thread` call. For example:\r\n\r\n```py\r\nimport rethread\r\n\r\ndef long_function(a: str, b: str, some_kwarg: str = 'c'):\r\n    ...\r\n\r\nthread: rethread.RunningThread = rethread.thread(long_function, 'a', 'b', some_kwarg = 'c')\r\n```\r\n\r\nIf you plan on always running a function in a thread, you can use `rethread.auto` to automatically thread a function:\r\n\r\n```py\r\n@rethread.auto\r\ndef long_function():\r\n    ...\r\n\r\nthread: rethread.RunningThread = long_function() # no need for a call to rethread.thread\r\n```\r\n\r\nTo get the return value of the threaded function, access the `RunningThread.value` attribute.\r\n\r\nAn error will be raised if the thread is still running, so make sure to call `wait()` on the thread.\r\n\r\n```py\r\n@rethread.auto\r\ndef long_function() -\u003e str:\r\n    ...\r\n\r\n    return 'hi'\r\n\r\nt = long_function()\r\nt.wait() # wait for the thread to finish\r\nprint(t.value) # hi\r\n```\r\n\r\nAlternatively, you can use the context manager syntax to automatically wait for the thread to finish:\r\n\r\n```py\r\n@rethread.auto\r\ndef long_function() -\u003e str:\r\n    ...\r\n\r\n    return 'hi'\r\n\r\nt = long_function()\r\nwith t:\r\n    do_something()\r\n    # once everything in this context is finished, rethread automatically waits for the thread to finish\r\n\r\nprint(t.value) # hi\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerointensity%2Frethread","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzerointensity%2Frethread","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerointensity%2Frethread/lists"}