task.py
Run your task asynchronously in the background and control/communicate with them.

Install
pip install task.py
Usage
Basic use case of task.py is to run some unit of work asynchronously (in a separate thread or process) while being able to control and communicate with that unit of work. Example:
Lets define a simple_task that:
Expects some arguments
Does some work (sleep) until signaled to stop
return “done.” as final result
` >>> def simple_task(t): # will receive a Task instance as first argument ... assert t.args[0] == 'hello' ... assert t.kwargs['world'] == 'world' ... while not t.stopped(): ... time.sleep(0.1) ... return 'done.' `
Next, create a Task instance with simple_task as unit to work. Additionally specify arguments expected by our sleep_task:
` >>> t1 = Task(simple_task, 'hello', world='world') >>> >>> # start our task asynchronously >>> t1.start() >>> >>> # after 1 second signal our task to stop >>> time.sleep(1) >>> t1.stop() >>> >>> t1.done True >>> >>> t1.result 'done.' >>> >>> t1.exception == None True `
Lets create a new Task instance, this time skipping the expected arguments:
` >>> t2 = Task(simple_task) >>> >>> # start our task asynchronously >>> t2.start() >>> >>> t2.done True >>> >>> # No result found >>> t2.result == None True >>> >>> # our task raised an exception >>> t2.exception IndexError('tuple index out of range',) `
Communicating with Task
Task provide a communication queue over which external threads can send data to the executing unit of work. Example:
Lets define a sleep_task which will receive amount of time to sleep over the communication queue:
` >>> def sleep_task(t): ... secs = t.recv() # recv API, default blocks until we have some data ... time.sleep(int(secs)) ... >>> t3 = Task(sleep_task) >>> t3.start() >>> >>> # our task is waiting >>> t3.done False >>> >>> # send 1 sec sleep time >>> t3.send(1) >>> >>> # alright, done >>> t3.done True `
Controllers
Task and Celery
Metadata
Release files for task.py 0.3
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 |
|---|---|---|---|---|
| task.py-0.3.tar.gz | 6.6 kB | Without provenance | Details for task.py-0.3.tar.gz |
Release files / task.py-0.3.tar.gz
| Download URL | task.py-0.3.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
083ffba0026927e1e69e8a2d06d0c0f9f422509b41a4e81b70e577e37f83e3da
|
|
BLAKE2b-256 checksum How to use checksums |
71347b0e44501b10bb36e27b1bcd541e9f23d86c98fa1e00c3365fbb4681c3a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for task.py 0.3
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.