semvec/pypi-packages huggingface dataset:
aiotimeout 0.0.4
Timeout context manager for asyncio Python
Requires Python: ~=3.5

# aiotimeout [![CircleCI](https://circleci.com/gh/michalc/aiotimeout.svg?style=svg)](https://circleci.com/gh/michalc/aiotimeout) [![Test Coverage](https://api.codeclimate.com/v1/badges/8de540239bd7d6566f58/test_coverage)](https://codeclimate.com/github/michalc/aiotimeout/test_coverage)

Timeout context manager for asyncio Python


## Usage

```python
from aiotimeout import timeout

# Will raise an asyncio.TimeoutError
with timeout(1):
    await asyncio.sleep(1.5)

# Will not raise anything
with timeout(1):
    await asyncio.sleep(0.5)
```

You can respond to a timeout from _outside_ the context by catching `asyncio.TimeoutError`

```python
try:
    with timeout(1):
        await asyncio.sleep(1.5)
        print('This line is not reached')
except asyncio.TimeoutError:
    print('Timed out')
```

or you can respond to a timeout from _inside_ the context by catching `asyncio.CancelledError` and re-raising.

```python
try:
    with timeout(1):
        try:
            await asyncio.sleep(1.5)
        except asyncio.CancelledError
            print('Doing some cleanup')
            raise
except asyncio.TimeoutError:
    print('Timed out')
```


## Differences to alternatives

- `asyncio.wait_for` does not offer a context manager. In some cases a context manager is clearer.

- `asyncio.wait_for` creates/uses an extra task. In some cases this is not necessary, and an extra task adds non-determinism in terms of sequence of operations.

- Clearer internal code [in the author's opinion]. Rather than a custom class, [contextlib.contextmanager](https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager) is used.
aiothrottler 0.0.16
Throttler for asyncio Python
Requires Python: ~=3.5

# aiothrottler [![CircleCI](https://circleci.com/gh/michalc/aiothrottler.svg?style=svg)](https://circleci.com/gh/michalc/aiothrottler) [![Test Coverage](https://api.codeclimate.com/v1/badges/e52e294a919c8974c133/test_coverage)](https://codeclimate.com/github/michalc/aiothrottler/test_coverage)

Throttler for asyncio Python


## Installation

```bash
pip install aiothrottler
```


## Usage

Create a shared `Throttler`, passing a minimum interval, e.g. `0.5` seconds

```python
from aiothrottler import Throttler

throttler = Throttler(min_interval=0.5)
```

and then just before the piece(s) of code to be throttled, _call_ this and `await` its result.

```python
await throttler()
# There will be a gap of at least 0.5 seconds
# between executions reaching this line
```


## Example: multiple tasks throttled

```python
import asyncio
import time

from aiothrottler import Throttler

async def main():
    throttler = Throttler(min_interval=0.5)
    await asyncio.gather(*[
        worker(throttler) for _ in range(10)
    ])

async def worker(throttler):
    await throttler()
    # Interval of at least 0.5 seconds between prints
    # even though all workers started together
    print(time.time())

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
```


## Example: single task throttled/smoothed

```python
import asyncio
import random
import time

from aiothrottler import Throttler

async def main():
    throttler = Throttler(min_interval=0.5)
    for _ in range(10):
        await throttler()
        # Interval of at least 0.5 seconds between prints
        # even though each sleep is random
        print(time.time())
        await asyncio.sleep(random.random())

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
```


## Differences to alternatives

- The API features a function to call to `await` its result [some use a context manager]

- The API is imperative [some use a functional approach/higher-order function]

- No polling is used [some use polling internally]

- A _minimum interval between resolutions_ is used to throttle [rather that a _max resolutions per time interval_, which can cause an irregular pattern of resolutions]

- The tests cover edge cases, such as asserting on throttling after tasks being throttled have been cancelled [some alternatives do not]
IHpip 0.1.0
Small package that makes requirement.txt files better

### IHpip
simple extension to the pip -r command which allows you to separate your dependencies
for different environments e.g. testing and production

sample requirements.yml
```yaml
test:
  - pytest
  - tox

prod:
  - pyyaml
```
to install the test dependencies run
```ihpip requirements.yml test```

this can also be used to separate python dependencies for different docker containers