{"id":19665231,"url":"https://github.com/alttch/neotasker","last_synced_at":"2025-04-28T22:31:04.566Z","repository":{"id":57445481,"uuid":"226962827","full_name":"alttch/neotasker","owner":"alttch","description":"Lightweight workers and task management library for Python","archived":false,"fork":false,"pushed_at":"2021-08-21T23:24:21.000Z","size":163,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T11:24:20.010Z","etag":null,"topics":["asyncio","event","interval","python3","queue","thread-pool","threadpoolexecutor","workers"],"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/alttch.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-12-09T20:36:41.000Z","updated_at":"2023-09-15T14:20:59.000Z","dependencies_parsed_at":"2022-09-26T17:30:53.894Z","dependency_job_id":null,"html_url":"https://github.com/alttch/neotasker","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/alttch%2Fneotasker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Fneotasker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Fneotasker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Fneotasker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alttch","download_url":"https://codeload.github.com/alttch/neotasker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251397577,"owners_count":21583034,"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":["asyncio","event","interval","python3","queue","thread-pool","threadpoolexecutor","workers"],"created_at":"2024-11-11T16:21:43.550Z","updated_at":"2025-04-28T22:31:04.199Z","avatar_url":"https://github.com/alttch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# neotasker\nLightweight Python library for modern thread / multiprocessing pooling and task\nprocessing via asyncio.\n\n\u003cimg src=\"https://img.shields.io/pypi/v/neotasker.svg\" /\u003e\n\u003cimg src=\"https://img.shields.io/badge/license-MIT-green.svg\" /\u003e\n\u003cimg src=\"https://img.shields.io/badge/python-3.5%20%7C%203.6%20%7C%203.7-blue.svg\" /\u003e\n\u003cimg src=\"https://img.shields.io/badge/-alpha-red.svg\" /\u003e\n\nNeotasker is lightweight variation of\n[atasker](https://github.com/alttch/atasker) library: tasks don't have\npriorities, go directly to ThreadPoolExecutor and are standard Python future\nobjects. This library is useful for the high-load projects with lightweight\ntasks as majority tasks are directly proxied to pool.\n\nNeotasker works on top of **ThreadPoolExecutor** and **asyncio** and provides\nadditional features:\n\n* Easy thread pool and asyncio loops initialization\n* Interval, queue and event-based workers\n* Built-in integration with [aiosched](https://github.com/alttch/aiosched)\n\n## Install\n\n```bash\npip3 install neotasker\n```\n\nSources: https://github.com/alttch/neotasker\n\nDocumentation: https://neotasker.readthedocs.io/\n\n## Code examples\n\n### Start/stop\n\n```python\n\nfrom neotasker import task_supervisor\n\n# set pool size\n# min_size='max' means pre-spawn all pool threads\ntask_supervisor.set_thread_pool(min_size='max', max_size=20)\ntask_supervisor.start()\n# ...\n# start workers, other threads etc.\n# ...\n# optionally block current thread\ntask_supervisor.block()\n\n# stop from any thread\ntask_supervisor.stop()\n```\n\n### Executing future\n\nYou may work with *neotasker.thread_pool* object directly or use\n*task_supervisor.spawn* function, which's directly mapped to\n*thread_pool.submit*)\n\n```python\nfrom neotasker import thread_pool\n\nthread_pool.start()\n\ndef mytask(a, b, c):\n    print(f'I am working in the background! {a} {b} {c}')\n    return 777\n\ntask = task_supervisor.spawn(mytask, 1, 2, c=3)\n\n# get future result\nresult = task.result()\n```\n### Creating async io loop\n\n```python\nfrom neotasker import thread_pool\n\nthread_pool.start()\ntask_supervisor.create_aloop('default', default=True)\n\n# The loop will until supervisor is stopped\n# Spawn coroutine from another thread:\n\ntask_supervisor.get_aloop().spawn_coroutine_threadsafe(coro)\n```\n\n### Worker examples\n\n```python\nfrom neotasker import background_worker, task_supervisor\n\ntask_supervisor.start()\n# we need to create at least one aloop to start workers\ntask_supervisor.create_aloop('default', default=True)\n# create one more async loop\ntask_supervisor.create_aloop('loop2')\n\n@background_worker\ndef worker1(**kwargs):\n    print('I am a simple background worker')\n\n@background_worker\nasync def worker_async(**kwargs):\n    print('I am async background worker')\n\n@background_worker(interval=1, loop='loop2')\ndef worker2(**kwargs):\n    print('I run every second!')\n\n@background_worker(queue=True)\ndef worker3(task, **kwargs):\n    print('I run when there is a task in my queue')\n\n@background_worker(event=True)\ndef worker4(**kwargs):\n    print('I run when triggered')\n\nworker1.start()\nworker_async.start()\nworker2.start()\nworker3.start()\nworker4.start()\n\nworker3.put_threadsafe('todo1')\nworker4.trigger_threadsafe()\n\nfrom neotasker import BackgroundIntervalWorker\n\nclass MyWorker(BackgroundIntervalWorker):\n\n    def run(self, **kwargs):\n        print('I am custom worker class')\n\nworker5 = MyWorker(interval=0.1, name='worker5')\nworker5.start()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falttch%2Fneotasker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falttch%2Fneotasker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falttch%2Fneotasker/lists"}