GithubHelp home page GithubHelp logo

darksidecat / aiopriman Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 177 KB

library for managing asyncio synchronization primitives

License: MIT License

Python 100.00%
synchronization-primitives asyncio lockmanager

aiopriman's Introduction

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
        )
    )

aiopriman's People

Contributors

darksidecat avatar

Stargazers

 avatar

Watchers

 avatar

aiopriman's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.