Skip to main content

library for managing asyncio synchronization primitives

Project description

Aiopriman

codecov PyPi Package Version PyPi status Supported python versions PyPI - Downloads MIT License

Attention! the project is at the initial stage of development, so there may be changes that break backward compatibility

This package provides the ability to manage asyncio synchronization primitives. Allows you to create storages of primitives, provides convenient means for accessing them using context managers, factories, creation and access to synchronization primitives by key.

Designed to solve the problem of managing dynamically created synchronization primitives for different resources.

Primitives are stored in memory only when needed.

Install

pip install aiopriman

Usage Examples

Working with a specific type of Manager, storage data must be specified as a parameter

import asyncio
import logging

from aiopriman.manager import LockManager, SemaphoreManager
from aiopriman.storage import StorageData


async def run_lock(storage, name):
    logging.debug(f"START Lock {name}")
    async with LockManager(storage_data=storage, key="test") as lock:
        logging.debug(f"HERE LOCKED {name}: {lock}")
        await asyncio.sleep(3)


async def run_sem(storage, name):
    logging.debug(f"START Sem {name}")
    async with SemaphoreManager(storage_data=storage,  key="test", value=2) as sem:
        logging.debug(f"HERE SEM LOCKED {name}: {sem}")
        await asyncio.sleep(3)


async def main_run(*args):
    await asyncio.gather(*args)


if __name__ == '__main__':
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(levelname)s:%(name)s:(%(filename)s).%(funcName)s(%(lineno)d):%(message)s'
    )

    tasks = []
    storage_data = StorageData()
    for i in range(1, 10):
        tasks.append(run_lock(storage_data, i))
        tasks.append(run_sem(storage_data, i))

    asyncio.run(
        main_run(
           *tasks
        )
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiopriman-0.2.3.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file aiopriman-0.2.3.tar.gz.

File metadata

  • Download URL: aiopriman-0.2.3.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for aiopriman-0.2.3.tar.gz
Algorithm Hash digest
SHA256 85f4ff6543979e90dbf036879014074706a902ce3f52d005ae0db49ce0800395
MD5 fb3f8c766bc1cb3a8c5fff41521e6fc1
BLAKE2b-256 baa9e6a8806d77ad38b323838de0bb86d8f4195ac799d3b167d67bc57a0f7643

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page