{"id":16220208,"url":"https://github.com/brianpugh/lox","last_synced_at":"2025-04-09T14:06:28.253Z","repository":{"id":41044924,"uuid":"187784241","full_name":"BrianPugh/lox","owner":"BrianPugh","description":"Threading and Multiprocessing made easy.","archived":false,"fork":false,"pushed_at":"2024-06-12T23:24:30.000Z","size":925,"stargazers_count":90,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-11T11:58:02.349Z","etag":null,"topics":["concurrency","multiprocessing","multithreading","mutex","semaphore"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrianPugh.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["BrianPugh"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2019-05-21T07:26:12.000Z","updated_at":"2024-08-13T14:27:51.000Z","dependencies_parsed_at":"2024-10-25T17:21:50.240Z","dependency_job_id":"8789611e-a6ab-4504-a7c6-fc9dfa509e75","html_url":"https://github.com/BrianPugh/lox","commit_stats":{"total_commits":254,"total_committers":4,"mean_commits":63.5,"dds":0.405511811023622,"last_synced_commit":"2c4b432c2ad82f9f1f899070b09771c786d6f64b"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianPugh%2Flox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianPugh%2Flox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianPugh%2Flox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianPugh%2Flox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrianPugh","download_url":"https://codeload.github.com/BrianPugh/lox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054227,"owners_count":21039952,"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":["concurrency","multiprocessing","multithreading","mutex","semaphore"],"created_at":"2024-10-10T11:58:08.825Z","updated_at":"2025-04-09T14:06:28.208Z","avatar_url":"https://github.com/BrianPugh.png","language":"Python","funding_links":["https://github.com/sponsors/BrianPugh"],"categories":[],"sub_categories":[],"readme":".. image:: assets/lox_200w.png\n\n\n.. image:: https://img.shields.io/pypi/v/lox.svg\n        :target: https://pypi.python.org/pypi/lox\n\n.. image:: https://circleci.com/gh/BrianPugh/lox.svg?style=svg\n        :target: https://circleci.com/gh/BrianPugh/lox\n\n.. image:: https://readthedocs.org/projects/lox/badge/?version=latest\n        :target: https://lox.readthedocs.io/en/latest/?badge=latest\n        :alt: Documentation Status\n\n\nThreading and multiprocessing made easy.\n\n\n* Free software: Apache-2.0 license\n* Documentation: https://lox.readthedocs.io.\n* Python \u003e=3.6\n\n\n**Lox** provides decorators and synchronization primitives to quickly add\nconcurrency to your projects.\n\nInstallation\n------------\n\n    pip3 install --user lox\n\nFeatures\n--------\n\n* **Multithreading**: Powerful, intuitive multithreading in just 2 additional lines of code.\n\n* **Multiprocessing**: Truly parallel function execution with the same interface as **multithreading**.\n\n* **Synchronization**: Advanced thread synchronization, communication, and resource management tools.\n\nTodos\n-----\n\n* All objects except ``lox.process`` are for threads. These will eventually be multiprocess friendly.\n\nUsage\n-----\n\nEasy Multithreading\n^^^^^^^^^^^^^^^^^^^\n\n    \u003e\u003e\u003e import lox\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e @lox.thread(4) # Will operate with a maximum of 4 threads\n    ... def foo(x,y):\n    ...     return x*y\n    \u003e\u003e\u003e foo(3,4) # normal function calls still work\n    12\n    \u003e\u003e\u003e for i in range(5):\n    ...     foo.scatter(i, i+1)\n    -ignore-\n    \u003e\u003e\u003e # foo is currently being executed in 4 threads\n    \u003e\u003e\u003e results = foo.gather() # block until results are ready\n    \u003e\u003e\u003e print(results) # Results are in the same order as scatter() calls\n    [0, 2, 6, 12, 20]\n\nOr, for example, if you aren't allowed to directly decorate the function you\nwould like multithreaded/multiprocessed, you can just directly invoke the\ndecorator:\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e # Lets say we don't have direct access to this function\n    ... def foo(x, y):\n    ...     return x * y\n    ...\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e def my_func():\n    ...     foo_threaded = lox.thread(foo)\n    ...     for i in range(5):\n    ...         foo_threaded.scatter(i, i + 1)\n    ...     results = foo_threaded.gather()\n    ...     # foo is currently being executed in default 50 thread executor pool\n    ...     return results\n    ...\n\n\nThis also makes it easier to dynamically control the number of\nthread/processes in the executor pool. The syntax is a little weird, but\nthis is just explicitly invoking a decorator that has optional arguments:\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e # Set the number of executer threads to 10\n    \u003e\u003e\u003e foo_threaded = lox.thread(10)(foo)\n\n\nEasy Multiprocessing\n^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e import lox\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e @lox.process(4)  # Will operate with a pool of 4 processes\n    ... def foo(x, y):\n    ...     return x * y\n    ...\n    \u003e\u003e\u003e foo(3, 4)  # normal function calls still work\n    12\n    \u003e\u003e\u003e for i in range(5):\n    ...     foo.scatter(i, i + 1)\n    ...\n    -ignore-\n    \u003e\u003e\u003e # foo is currently being executed in 4 processes\n    \u003e\u003e\u003e results = foo.gather()  # block until results are ready\n    \u003e\u003e\u003e print(results)  # Results are in the same order as scatter() calls\n    [0, 2, 6, 12, 20]\n\n\nProgress Bar Support (tqdm)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e import lox\n    \u003e\u003e\u003e from random import random\n    \u003e\u003e\u003e from time import sleep\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e @lox.thread(2)\n    ... def foo(multiplier):\n    ...     sleep(multiplier * random())\n    ...\n    \u003e\u003e\u003e for i in range(10):\n    \u003e\u003e\u003e     foo.scatter(i)\n    \u003e\u003e\u003e results = foo.gather(tqdm=True)\n    90%|████████████████████████████████▌        | 9/10 [00:03\u003c00:00,  1.32it/s]\n    100%|███████████████████████████████████████| 10/10 [00:06\u003c00:00,  1.46s/it]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianpugh%2Flox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrianpugh%2Flox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianpugh%2Flox/lists"}