{"id":26272958,"url":"https://github.com/supercoderhawk/flask-threads","last_synced_at":"2025-07-13T06:40:08.053Z","repository":{"id":280601700,"uuid":"942537916","full_name":"supercoderhawk/flask-threads","owner":"supercoderhawk","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-04T09:07:31.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-04T10:23:12.440Z","etag":null,"topics":[],"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/supercoderhawk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2025-03-04T09:04:22.000Z","updated_at":"2025-03-04T09:07:34.000Z","dependencies_parsed_at":"2025-03-04T10:23:14.381Z","dependency_job_id":"636a4c78-f18e-4015-b56f-04fe4b4fd8ae","html_url":"https://github.com/supercoderhawk/flask-threads","commit_stats":null,"previous_names":["supercoderhawk/flask-threads"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercoderhawk%2Fflask-threads","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercoderhawk%2Fflask-threads/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercoderhawk%2Fflask-threads/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercoderhawk%2Fflask-threads/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supercoderhawk","download_url":"https://codeload.github.com/supercoderhawk/flask-threads/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243544642,"owners_count":20308169,"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":"2025-03-14T08:14:00.183Z","updated_at":"2025-03-14T08:14:00.660Z","avatar_url":"https://github.com/supercoderhawk.png","language":"Python","readme":"## Flask-Threads\n[![Actions Status](https://github.com/sintezcs/flask-threads/workflows/GitHub%20Build/badge.svg)](https://github.com/sintezcs/flask-threads/actions)\n\nA helper library to work with threads within Flask applications.\n\nThe main problem that you face trying to spin a background thread or running a \nfuture in Flask app - is loosing the application context. The most common \nscenario is to try to access `flask.g` object. Application context \nis a thread local so you can not access it from another thread and Flask will \nraise an exception if you would try to. \n\nThis library provides helper classes that allows you accessing the current \napplication context from another thread.\n\n**Warning! Alpha-version, use at your own risk.**\n\n**This is a extended version from https://github.com/sintezcs/flask-threads**\n\n### Installation\n```bash\n$ pip install Flask-Threads-Ext\n```\n\n### Examples\n\n#### Threads\n\n```python\nfrom flask import g\nfrom flask import request\nfrom flask import Flask\nfrom flask_threads_ext import AppContextThread\n\napp = Flask('my_app')\n\n\n@app.route('/user')\ndef get_user():\n    g.user_id = request.headers.get('user-id')\n    t = AppContextThread(target=do_some_user_work_in_another_thread)\n    t.start()\n    t.join()\n    return 'ok'\n\n\ndef do_some_user_work_in_another_thread():\n    id = g.user_id\n    print(id)\n\n```\n\n#### Concurrent futures\n\n```python\nfrom flask import g\nfrom flask import request\nfrom flask import Flask\nfrom flask_threads_ext import ThreadPoolWithAppContextExecutor\n\napp = Flask('my_app')\n\n\n@app.route('/user')\ndef get_user():\n    g.user_id = request.headers.get('user-id')\n    with ThreadPoolWithAppContextExecutor(max_workers=2) as pool:\n        future = pool.submit(do_some_user_work_in_another_thread)\n        future.result()\n    return 'ok'\n\n\ndef do_some_user_work_in_another_thread():\n    id = g.user_id\n    print(id)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercoderhawk%2Fflask-threads","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupercoderhawk%2Fflask-threads","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercoderhawk%2Fflask-threads/lists"}