WorkerIO
Project description
WorkerIO
A tool that allows you to create your own workers and distribute work among them.
Each worker creates its own thread in which it will fetch jobs from the queue.SimpleQueue queue and execute them in its execute method.
The result of the job is returned using asyncio.Future.
[!WARNING] Since everything will be executed in another thread, use thread-safe functions. Do not modify files unless you are sure they are not open in another worker.
Installing
[!NOTE] TODO
Basic examples
import workerio
from asyncio import new_event_loop
from requests import get
class MyUrlWorker(workerio.Worker):
def execute(self, url: str):
return get(url).text
manager = workerio.Manager()
manager.add_worker(MyUrlWorker())
async def main():
manager.start_all()
result = await manager.put_work(MyUrlWorker, "https://example.com")
print(result)
manager.stop_all_nowait()
if __name__ == "__main__":
loop = new_event_loop()
loop.run_until_complete(main())
import workerio
from asyncio import Future
class MyManager(workerio.Manager):
def put_work(self, worker_type, *args, **kwargs) -> Future:
suitable_workers = self.get_suitable_workers(worker_type, *args, **kwargs)
if len(suitable_workers) == 0:
raise workerio.SuitableWorkerNotFound()
selected_worker = suitable_workers[0]
for worker in suitable_workers:
if worker.qsize == 0 and worker.check(*args, **kwargs):
selected_worker = worker
break
return selected_worker.put_job(*args, **kwargs)
manager = MyManager()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file workerio-0.1.0.tar.gz.
File metadata
- Download URL: workerio-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
406ef30ad2247168b76e185091a99b7115d6f6b7427cda14fddbe50fb33b8022
|
|
| MD5 |
758b27fd07b6000652d71e3de52fdc28
|
|
| BLAKE2b-256 |
601edd267ddd811c7e144490707db80255320fb3ed2b628c2b1ffc3a46ae660f
|
File details
Details for the file workerio-0.1.0-py3-none-any.whl.
File metadata
- Download URL: workerio-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b96946a635541ffaa777aa95e46bc5faf2aea88526c9f4ac99e63af6e7ed398
|
|
| MD5 |
be41566c34bd4f083fd2ae29307b810f
|
|
| BLAKE2b-256 |
e83faaf2980cbab3842254693b02946c6113b745ac8dfcc26db2ebe6644a1059
|