You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

aiofreqlimit

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aiofreqlimit - pypi Package Compare versions

Comparing version
0.0.14
to
0.0.15
+2
-4
aiofreqlimit.egg-info/PKG-INFO
Metadata-Version: 2.1
Name: aiofreqlimit
Version: 0.0.14
Version: 0.0.15
Summary: Frequency limit for asyncio

@@ -11,4 +11,2 @@ Home-page: https://github.com/gleb-chipiga/aiofreqlimit

Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11

@@ -23,3 +21,3 @@ Classifier: Programming Language :: Python :: 3.12

Classifier: Framework :: AsyncIO
Requires-Python: >=3.9,<3.13
Requires-Python: >=3.11,<3.13
Description-Content-Type: text/x-rst

@@ -26,0 +24,0 @@ License-File: LICENSE

import asyncio
from contextlib import AsyncExitStack, asynccontextmanager, suppress
from types import TracebackType
from typing import AsyncIterator, Dict, Final, Hashable, Optional, Type
from typing import AsyncIterator, Final, Hashable
__all__ = ("FreqLimit", "__version__")
__version__ = "0.0.14"
__version__ = "0.0.15"

@@ -12,4 +12,4 @@

def __init__(self) -> None:
self._ts: float = -float("inf")
self._count: int = 0
self._ts = -float("inf")
self._count = 0
self._lock: Final = asyncio.Lock()

@@ -31,5 +31,5 @@

self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:

@@ -47,3 +47,7 @@ try:

class FreqLimit:
def __init__(self, interval: float, clean_interval: float = 0) -> None:
def __init__(
self,
interval: float,
clean_interval: float = 0,
) -> None:
if interval <= 0:

@@ -55,13 +59,16 @@ raise RuntimeError("Interval must be greater than 0")

)
self._interval: Final[float] = interval
self._clean_interval: Final[float] = (
self._interval: Final = interval
self._clean_interval: Final = (
clean_interval if clean_interval > 0 else interval
)
self._locks: Final[Dict[Hashable, Lock]] = {}
self._locks: Final = dict[Hashable, Lock]()
self._clean_event: Final = asyncio.Event()
self._clean_task: Optional[asyncio.Task[None]] = None
self._clean_task: asyncio.Task[None] | None = None
self._loop: Final = asyncio.get_running_loop()
@asynccontextmanager
async def resource(self, key: Hashable = None) -> AsyncIterator[None]:
async def resource(
self,
key: Hashable = None,
) -> AsyncIterator[None]:
if self._clean_task is None:

@@ -68,0 +75,0 @@ self._clean_task = asyncio.create_task(self._clean())

MIT License
Copyright (c) 2018-2020 Gleb Chipiga
Copyright (c) 2018-2024 Gleb Chipiga

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

Metadata-Version: 2.1
Name: aiofreqlimit
Version: 0.0.14
Version: 0.0.15
Summary: Frequency limit for asyncio

@@ -11,4 +11,2 @@ Home-page: https://github.com/gleb-chipiga/aiofreqlimit

Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11

@@ -23,3 +21,3 @@ Classifier: Programming Language :: Python :: 3.12

Classifier: Framework :: AsyncIO
Requires-Python: >=3.9,<3.13
Requires-Python: >=3.11,<3.13
Description-Content-Type: text/x-rst

@@ -26,0 +24,0 @@ License-File: LICENSE

@@ -14,3 +14,3 @@ [tool.isort]

[tox]
envlist = py39,py310,py311,py312
envlist = py311,py312

@@ -17,0 +17,0 @@ [testenv]

@@ -25,4 +25,2 @@ import re

"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",

@@ -40,3 +38,3 @@ "Programming Language :: Python :: 3.12",

package_data={"aiofreqlimit": ["py.typed"]},
python_requires=">=3.9,<3.13",
python_requires=">=3.11,<3.13",
tests_require=[

@@ -43,0 +41,0 @@ "pytest",

import asyncio
from contextlib import suppress
from random import uniform
from typing import List, Tuple, cast
from typing import cast
from weakref import ref

@@ -88,7 +88,6 @@

loop = asyncio.get_running_loop()
time_marks = Tuple[float, float, float]
async def limit(
_freq_limit: aiofreqlimit.FreqLimit, interval: float
) -> time_marks:
) -> tuple[float, float, float]:
time1 = loop.time()

@@ -103,3 +102,6 @@ async with _freq_limit.resource("key"):

tasks = (limit(freq_limit, uniform(0, 0.1)) for _ in range(5))
intervals = cast(List[time_marks], await asyncio.gather(*tasks))
intervals = cast(
list[tuple[float, float, float]],
await asyncio.gather(*tasks),
)
assert all(isinstance(value, tuple) for value in intervals)

@@ -192,3 +194,3 @@ intervals = sorted(intervals, key=lambda interval: interval[0])

loop = asyncio.get_running_loop()
intervals: List[float] = []
intervals: list[float] = []
time = loop.time()

@@ -195,0 +197,0 @@ freq_limit = aiofreqlimit.FreqLimit(0.05)