{"id":16105856,"url":"https://github.com/devlights/pylatch","last_synced_at":"2025-04-06T03:13:41.098Z","repository":{"id":149716721,"uuid":"134649733","full_name":"devlights/pylatch","owner":"devlights","description":"This is CountDownLatch implementations for Python.","archived":false,"fork":false,"pushed_at":"2018-05-25T02:39:14.000Z","size":13,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-12T08:58:43.790Z","etag":null,"topics":["library","python","python3"],"latest_commit_sha":null,"homepage":null,"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/devlights.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":"2018-05-24T02:23:14.000Z","updated_at":"2018-05-25T02:39:16.000Z","dependencies_parsed_at":"2023-04-25T15:01:34.499Z","dependency_job_id":null,"html_url":"https://github.com/devlights/pylatch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlights%2Fpylatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlights%2Fpylatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlights%2Fpylatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlights%2Fpylatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devlights","download_url":"https://codeload.github.com/devlights/pylatch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427012,"owners_count":20937214,"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":["library","python","python3"],"created_at":"2024-10-09T19:10:55.670Z","updated_at":"2025-04-06T03:13:41.077Z","avatar_url":"https://github.com/devlights.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pylatch\nJava や C# に存在する CountDownLatch を Python で簡易実装したものです。\n\n(C# の場合は、 CountDownEvent がそれに当たる)\n\nマルチスレッド版とマルチプロセス版があります。\n\nどちらもクラス名は CountDownLatch です。\n\n## 使い方 (マルチスレッド用)\n\n利用するクラスは ```pylatch.threadlatch.CountDownLatch``` となります。\n\n```python\n\u003e\u003e\u003e # ---------------------------------------------\n\u003e\u003e\u003e # スレッド処理で利用する場合\n\u003e\u003e\u003e # ---------------------------------------------\n\u003e\u003e\u003e import threading as th\n\u003e\u003e\u003e import pylatch.threadlatch as pl\n\n\u003e\u003e\u003e latch = pl.CountDownLatch(2)\n\u003e\u003e\u003e th1 = th.Thread(target=lambda: latch.count_down())\n\u003e\u003e\u003e th2 = th.Thread(target=lambda: latch.count_down())\n\n\u003e\u003e\u003e latch.count\n2\n\u003e\u003e\u003e latch.await(timeout=1.0)\nFalse\n\n\u003e\u003e\u003e th1.start()\n\u003e\u003e\u003e th1.join()\n\u003e\u003e\u003e latch.count\n1\n\u003e\u003e\u003e latch.await(timeout=1.0)\nFalse\n\n\u003e\u003e\u003e th2.start()\n\u003e\u003e\u003e th2.join()\n\u003e\u003e\u003e latch.count\n0\n\u003e\u003e\u003e latch.await(timeout=1.0)\nTrue\n```\n\n## 使い方 (マルチプロセス用)\n\n利用するクラスは ```pylatch.processlatch.CountDownLatch``` となります。\n\n```python\n\u003e\u003e\u003e # ---------------------------------------------\n\u003e\u003e\u003e # マルチプロセス処理で利用する場合\n\u003e\u003e\u003e # ---------------------------------------------\n\u003e\u003e\u003e import multiprocessing as mp\n\u003e\u003e\u003e import pylatch.processlatch as pl\n\n\u003e\u003e\u003e latch = pl.CountDownLatch(2)\n\u003e\u003e\u003e proc1 = mp.Process(target=pl.__for_doctest, args=(latch,))\n\u003e\u003e\u003e proc2 = mp.Process(target=pl.__for_doctest, args=(latch,))\n\n\u003e\u003e\u003e latch.count\n2\n\u003e\u003e\u003e latch.await(timeout=1.0)\nFalse\n\n\u003e\u003e\u003e proc1.start()\n\u003e\u003e\u003e proc1.join()\n\u003e\u003e\u003e latch.count\n1\n\u003e\u003e\u003e latch.await(timeout=1.0)\nFalse\n\n\u003e\u003e\u003e proc2.start()\n\u003e\u003e\u003e proc2.join()\n\u003e\u003e\u003e latch.count\n0\n\u003e\u003e\u003e latch.await(timeout=1.0)\nTrue\n```\n\n## テスト\n\n```sh\n$ python -m unittest\n```\n\n# 参考情報\n\n以下の情報を参考にさせていただきました。\n\n- [Does Python have a similar control mechanism to Java's CountDownLatch?\n](https://stackoverflow.com/questions/10236947/does-python-have-a-similar-control-mechanism-to-javas-countdownlatch)\n- [Python で Java の CountDownLatch を実装してみる](https://qiita.com/shinkiro/items/75f3561d6bc96694ce30)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlights%2Fpylatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevlights%2Fpylatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlights%2Fpylatch/lists"}