countdown-event
A synchronization class which blocks when the count is not zero.
Here's an example
import asyncio
from countdown_event import CountdownEvent
async def long_running_task(countdown_event,cancellation_event):
count = countdown_event.increment()
print(f'incremented count to {count}')
try:
print('Waiting for cancellation event')
await cancellation_event.wait()
finally:
count = countdown_event.decrement()
print(f'decremented count to {count}')
async def stop_tasks(secs, countdown_event, cancellation_event):
print(f'waiting {secs} seconds before setting the cancellation event')
await asyncio.sleep(secs)
print('setting the cancellation event')
cancellation_event.set()
print('waiting for tasks to finish')
await countdown_event.wait()
print('countdown event cleared')
async def main_async():
cancellation_event = asyncio.Event()
countdown_event = CountdownEvent()
tasks = [
long_running_task(countdown_event, cancellation_event),
long_running_task(countdown_event, cancellation_event),
long_running_task(countdown_event, cancellation_event),
stop_tasks(5, countdown_event, cancellation_event)
]
await asyncio.wait(tasks)
assert countdown_event.count == 0
print("done")
if __name__ == "__main__":
asyncio.run(main_async())
Here's the output.
incremented count to 1
Waiting for cancellation event
incremented count to 2
Waiting for cancellation event
waiting 5 seconds before setting the cancellation event
incremented count to 3
Waiting for cancellation event
setting the cancellation event
waiting for tasks to finish
decremented count to 2
decremented count to 1
decremented count to 0
countdown event cleared
done
Metadata
Release files for countdown-event 0.1.0
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 |
|---|---|---|---|---|
| countdown-event-0.1.0.tar.gz | 6.0 kB | Without provenance | Details for countdown-event-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| countdown_event-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for countdown_event-0.1.0-py3-none-any.whl |
Total release size: 12.2 kB
Release files / countdown-event-0.1.0.tar.gz
| Download URL | countdown-event-0.1.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e7c316f3534d2f64f448808b3d4f6932d71f055364129bbf380e59d55bf3ec4
|
|
BLAKE2b-256 checksum How to use checksums |
34cfe87d281df032dfb8c8385f459eddbb382e5e8a65ff8f8ef757ccab6e61b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.1 Linux/4.10.0-33-generic
|
Release files / countdown_event-0.1.0-py3-none-any.whl
| Download URL | countdown_event-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07b811a6a68d2288783b1d22908639f577014bdd3b9c38d534507852b5c5aa78
|
|
BLAKE2b-256 checksum How to use checksums |
6fc8421d3bbb181e1c4c6a0f74f8bbc18810d1dcfe6654131331e3749e7e1950
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.1 Linux/4.10.0-33-generic
|
Security for countdown-event 0.1.0
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.