{"id":24016453,"url":"https://github.com/zechcodes/oodle","last_synced_at":"2025-06-15T12:07:23.784Z","repository":{"id":265592101,"uuid":"895684078","full_name":"ZechCodes/Oodle","owner":"ZechCodes","description":"Oodle is a Python package that makes it easier to manage threads.","archived":false,"fork":false,"pushed_at":"2024-12-13T00:10:04.000Z","size":128,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T20:17:11.444Z","etag":null,"topics":["free-threaded","free-threading","python","python3","thread-groups","threading"],"latest_commit_sha":null,"homepage":"","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/ZechCodes.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-28T17:14:14.000Z","updated_at":"2024-12-13T00:10:08.000Z","dependencies_parsed_at":"2024-11-30T03:27:48.137Z","dependency_job_id":"d68e1bf5-5d2d-4eb3-8f2f-7f150b35899b","html_url":"https://github.com/ZechCodes/Oodle","commit_stats":null,"previous_names":["zechcodes/oodle"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ZechCodes/Oodle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FOodle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FOodle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FOodle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FOodle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZechCodes","download_url":"https://codeload.github.com/ZechCodes/Oodle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZechCodes%2FOodle/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259971378,"owners_count":22940012,"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":["free-threaded","free-threading","python","python3","thread-groups","threading"],"created_at":"2025-01-08T08:51:27.280Z","updated_at":"2025-06-15T12:07:23.766Z","avatar_url":"https://github.com/ZechCodes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Oodle\n\nOodle is a package that makes it easier to manage threads.\n\n## Installation\n\n```bash\npip install oodle\n```\n\n## Usage\n\n```python\nfrom oodle import spawn\n\n\ndef foo(message):\n    print(message)\n\n    \nspawn[foo](\"Hello World!\").wait()\n```\n\nThat spawns a thread, runs the function `foo` with the argument `\"Hello World!\"`, and waits for it to finish.\n\nSpawned threads return an `oodle.threads.Thread` which provides a `wait` method that blocks until the thread finishes and an `is_alive` property that returns `True` if the thread is still running.\n\n### Thread Groups\n\n```python\nfrom oodle import ThreadGroup\n\n\ndef foo(message):\n    print(message)\n\n\nwith ThreadGroup() as group:\n    group.spawn[foo](\"Hello World!\")\n    group.spawn[foo](\"Goodbye World!\")\n```\n\nThat spawns two threads, runs the function `foo` with the argument `\"Hello World!\"` in one thread and `\"Goodbye World!\"` in the other, and waits for both to finish.\n\nIf any thread in a thread group raises an exception, all other threads are stopped and the exception is raised in the calling thread.\n\n### Channels\n\n```python\nfrom oodle import Channel, ThreadGroup\n\ndef foo(message, channel):\n    channel.put(message)\n\nwith Channel() as channel:\n    with ThreadGroup() as group:\n        group.spawn[foo](\"Hello World!\", channel)\n        group.spawn[foo](\"Goodbye World!\", channel)\n\n    message_a, message_b = channel\n    print(message_a, message_b)\n```\n\nChannels also provide a `get` method and an `is_empty` property.\n\nAdditionally, the channel type provides a way to select the first message that arrives and stop all threads.\n\n```python\nfrom oodle import Channel\nfrom oodle.utilities import sleep\n\ndef foo(channel):\n    channel.put(\"Hello World!\")\n    \ndef bar(channel):\n    sleep(1)\n    channel.put(\"Goodbye World!\")\n    \nresult = Channel.get_first(foo, bar)\nprint(result)  # \"Hello World!\"\n```\n\nInternally this uses a thread group to spawn the functions and a channel to communicate between them. So if any of the functions raises an exception, all other threads are stopped and the exception is raised in the calling thread. If no exception is raised, all threads will be stopped after the first message arrives.\n\n### Shields\n\nThreads can use shields to protect against interruption during critical sections.\n\n```python\nfrom oodle import Shield, spawn, sleep\n\n\ndef foo():\n    with Shield():\n        sleep(1)\n\n\nthread = spawn[foo]()\nthread.stop(0.1)  # Raises TimeoutError\n```\n\n### Blocking \u0026 Patching\n\nTo enable thread interruption it is necessary to not use anything that can block the thread indefinitely. A great example is `time.sleep`. To avoid this use `oodle.sleep` instead. It is possible to patch `time.sleep` with `oodle.sleep` by importing `oodle.patches.patch_time` before any other modules.\n\n```python\nimport oodle.patches\noodle.patches.patch_time()\n\nfrom time import sleep\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzechcodes%2Foodle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzechcodes%2Foodle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzechcodes%2Foodle/lists"}