coworker
Generic worker that performs concurrent tasks using coroutine.
Quick Start Tutorial
Define how a task is performed – do_task takes a single input and optionally returns a result:
from coworker import Coworker
class SquareWorker(Coworker):
async def do_task(self, task): # Task can be anything, such as a tuple with a callable and args.
return task * task
Now let’s do some work:
import asyncio
async def background_worker_example():
worker = SquareWorker(max_concurrency=5) # Only 5 tasks will run concurrently. Defalts to 10
# Single task
result = await worker.do(2)
print(result) # result = 4
# Mulitiple tasks -- get all results after everything is done
tasks = list(range(100))
results = await worker.do(tasks)
print(results) # results = [0, 1, 4, 9, ...]
# Mulitiple tasks -- get first completed
tasks = list(range(10))
for result in worker.do(tasks, as_iterator=True):
print(await result) # results = 0, 1, 4, 9, ...
# Run async usage example
asyncio.run(background_worker_example())
Besides max_concurrency, you can also pass the following params to Coworker:
sliding_window to use sliding window or tumbling window when processing the tasks concurrently. Defaults to True.
do_task for a callable to do the task instead of having to sub-class. E.g. Coworker(do_task=lamdba x: x * x)
Links & Contact Info
Metadata
Release files for coworker 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| coworker-2.0.1.tar.gz | 14.0 kB | Without provenance | Details for coworker-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| coworker-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for coworker-2.0.1-py3-none-any.whl |
Total release size: 19.5 kB
Release files / coworker-2.0.1.tar.gz
| Download URL | coworker-2.0.1.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1bdf9b2c2feb368715434524ac5fda8d518fbff3b8827c7ee31c47eee46668f7
|
|
BLAKE2b-256 checksum How to use checksums |
05cd0bbed485ed06e1c82450a51a29d45926531a8b3e8d5e6838ed0b873cbd49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / coworker-2.0.1-py3-none-any.whl
| Download URL | coworker-2.0.1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51550ae1003b68b2e41ccbffbbdb058bda4b0b7734c3466adfda3e70999a77ea
|
|
BLAKE2b-256 checksum How to use checksums |
65537fd132410d8914154e10f41c89c285c4dadf408ca5e67a138387e90c04e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for coworker 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.