{"id":19297996,"url":"https://github.com/dotpot/soon","last_synced_at":"2025-04-22T09:32:06.086Z","repository":{"id":52700594,"uuid":"172889618","full_name":"dotpot/Soon","owner":"dotpot","description":"Worker decorator for background tasks re-using ThreadPoolExecutor.","archived":false,"fork":false,"pushed_at":"2022-12-08T01:49:50.000Z","size":16,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T14:44:27.308Z","etag":null,"topics":["background-jobs","python","python37","threading"],"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/dotpot.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":"2019-02-27T09:58:08.000Z","updated_at":"2024-07-18T22:38:24.000Z","dependencies_parsed_at":"2023-01-24T09:00:06.517Z","dependency_job_id":null,"html_url":"https://github.com/dotpot/Soon","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotpot%2FSoon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotpot%2FSoon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotpot%2FSoon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotpot%2FSoon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotpot","download_url":"https://codeload.github.com/dotpot/Soon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250215270,"owners_count":21393767,"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":["background-jobs","python","python37","threading"],"created_at":"2024-11-09T23:06:39.898Z","updated_at":"2025-04-22T09:32:05.806Z","avatar_url":"https://github.com/dotpot.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Soon\nWorker decorator for background tasks re-using [ThreadPoolExecutor](https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor).\n\nInstallation\n------------\n\nSoon is conveniently available via pip:\n```\npip install soon\n```\n\nor installable via `git clone` and `setup.py`\n```\ngit clone git@github.com:dotpot/Soon.git\nsudo python setup.py install\n```\n\nTo ensure Soon is properly installed, you can run the unittest suite from the project root:\n```\npipenv run pytest -v \n```\n\nUsage\n-----\nThe Soon library enables you to utilize the benefits of multi-threading with minimal concern about the implementation details.\n\n\nWebsite fetcher example\n-----------------\nYou've collected a list of urls and are looking to download the HTML of the lot.  The following is a perfectly reasonable first stab at solving the task.\n\n```python\nurls = [\n    'https://cnn.com',\n    'https://news.ycombinator.com/',\n    'https://stackoverflow.com/',\n]\n```\n---\n```python\nimport time\nimport requests\n\ndef fetch(url):\n    return requests.get(url)\n\nif __name__ == \"__main__\":\n\n    start = time.time()\n    responses = [fetch(url) for url in urls]\n    html = [response.text for response in responses]\n    end = time.time()\n    print(\"Time: %f seconds\" % (end - start))\n```\n---\n\nMore efficient website fetcher example\n--------------------------\n\nUsing Soon's decorator syntax, we can define a function that executes in multiple threads.  Individual calls to `download` are non-blocking, but we can largely ignore this fact and write code identically to how we would in a synchronous paradigm. \n\n```python\nimport time\nimport requests\n\nfrom soon import workers\n\n@workers(5)\ndef fetch(url):\n    return requests.get(url)\n\nif __name__ == \"__main__\":\n    start = time.time()\n    responses = [fetch(url) for url in urls]\n    html = [response.text for response in responses]\n    end = time.time()\n    print(\"Time: %f seconds\" % (end - start))\n\n```\nWe can now download websites more efficiently.\n\n---\n\nYou can also optionally pass in `timeout` argument, to prevent hanging on a task that is not guaranteed to return.\n\n```python\nimport time\n\nfrom soon import workers\n\n@workers(1, timeout=0.1)\ndef timeout_error():\n    time.sleep(1)\n\nif __name__ == \"__main__\":\n    timeout_error()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotpot%2Fsoon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotpot%2Fsoon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotpot%2Fsoon/lists"}