All Projects → python-trio → trimeter

python-trio / trimeter

Licence: other
(not ready yet) A simple but powerful job scheduler for Trio programs

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to trimeter

Trio
Trio – a friendly Python library for async concurrency and I/O
Stars: ✭ 4,404 (+9075%)
Mutual labels:  async-await, trio
Itiriri Async
A library for asynchronous iteration.
Stars: ✭ 78 (+62.5%)
Mutual labels:  map, async-await
sphinxcontrib-trio
Make Sphinx better at documenting Python functions and methods
Stars: ✭ 26 (-45.83%)
Mutual labels:  async-await, trio
nardis
A small web framework based on ASGI
Stars: ✭ 14 (-70.83%)
Mutual labels:  async-await
apr
this is like caolan/async which is like lodash but async, but awaitful
Stars: ✭ 75 (+56.25%)
Mutual labels:  async-await
autocomplete
Simple accessible autocomplete for vanilla javacript with support for remote & local data, ~3KB gzip
Stars: ✭ 38 (-20.83%)
Mutual labels:  async-await
PHPCoord
PHPCoord is a PHP library to aid in handling coordinates. It can convert coordinates for a point from one system to another and also calculate distance between points
Stars: ✭ 78 (+62.5%)
Mutual labels:  map
transit
Massively real-time city transit streaming application
Stars: ✭ 20 (-58.33%)
Mutual labels:  map
modern-javascript
👨‍🏫 Mike's Modern JavaScript course
Stars: ✭ 14 (-70.83%)
Mutual labels:  async-await
object-detection-notebooks
Object detection and localization with Tensorflow 2 and Keras
Stars: ✭ 25 (-47.92%)
Mutual labels:  map
AndroidOfflineMapLibrary
Offline OpenStreet Map Library (No Internet Required) You dont have to even one-time connect!
Stars: ✭ 16 (-66.67%)
Mutual labels:  map
AhaAlgorithms
《啊哈算法》书上代码
Stars: ✭ 47 (-2.08%)
Mutual labels:  map
LiveAtlas
A Dynmap, Squaremap, Pl3xmap and Overviewer frontend for the modern web
Stars: ✭ 168 (+250%)
Mutual labels:  map
stateless-future
Asynchronous programming in fully featured Scala syntax.
Stars: ✭ 14 (-70.83%)
Mutual labels:  async-await
observable ish
Observable state and events for browser and Flutter.
Stars: ✭ 26 (-45.83%)
Mutual labels:  map
mundraub-android
📱Android App for Mundraub, Na-Ovoce and other fruit maps
Stars: ✭ 30 (-37.5%)
Mutual labels:  map
diablo2
Utilities to work with diablo2, Clientless map rendering & packet sniffing
Stars: ✭ 126 (+162.5%)
Mutual labels:  map
map
🏳️‍🌈🗺 A map of community centers and other helpful information for queer (LGBTQ) people.
Stars: ✭ 15 (-68.75%)
Mutual labels:  map
async-enumerable-dotnet
Experimental operators for C# 8 IAsyncEnumerables
Stars: ✭ 32 (-33.33%)
Mutual labels:  async-await
jpndistrict
🗾 Create Japansese Administration Area Maps
Stars: ✭ 18 (-62.5%)
Mutual labels:  map
Join chatroom Documentation Status Latest PyPi version Automated test status Test coverage

Warning

This library isn't ready for release yet. Feedback welcome!

Trimeter

Trio is a friendly Python library for async concurrency and networking. Trimeter is a simple but powerful job scheduler for programs using Trio, released under your choice of the MIT or Apache 2 licenses.

Trimeter's core purpose is to make it easy to execute lots tasks concurrently, with rich options to control the degree of concurrency and to collect the task results.

Say you have 1000 urls that you want to fetch and process somehow:

# Old slow way
for url in urls:
    await fetch_and_process(url)

That's slow, so you want to do several at the same time... but to avoid overloading the network, you want to limit it to at most 5 calls at once. Oh, and there's a request quota, so we have to throttle it down to 1 per second. No problem:

# New and fancy way
await trimeter.run_on_each(
    fetch_and_process, urls, max_at_once=5, max_per_second=1
)

What if we don't know the whole list of urls up front? No worries, just pass in an async iterable instead, and Trimeter will do the right thing.

What if we want to get the result from each call as it finishes, so we can do something further with it? Just use amap (= short for "async map"):

async with trimeter.amap(fetch_and_process, urls, ...) as results:
    # Then iterate over the return values, as they become available
    # (i.e., not necessarily in the original order)
    async for result in results:
        ...

Of course amap also accepts throttling options like max_at_once, max_per_second, etc.

What if we want to use the outcome library to capture exceptions, so one call crashing doesn't terminate the whole program? And also, we want to pass through the original url alongside each result, so we know which result goes with which url?

async with trimeter.amap(
    fetch_and_process,
    urls,
    capture_outcome=True,
    include_value=True,
) as outcomes:
    # Then iterate over the return values, as they become available
    # (i.e., not necessarily in the original order)
    async for url, outcome in outcomes:
        try:
            return_value = outcome.unwrap()
        except Exception as exc:
            print(f"error while processing {url}: {exc!r}")

What if we just want to call a few functions in parallel and then get the results as a list, like asyncio.gather or Promise.all?

return_values = await trimeter.run_all([
    async_fn1,
    async_fn2,
    functools.partial(async_fn3, extra_arg, kwarg="yeah"),
])

Of course, this takes all the same options as the other functions, so you can control the degree of parallelism, use capture_outcome to capture exceptions, and so forth.

For more details, see the fine manual.

Can you summarize that in iambic trimeter?

Iambic trimeter? No problem:

Trimeter gives you tools
for running lots of tasks
to do your work real fast
but not so fast you crash.

Code of conduct

Contributors are requested to follow our code of conduct in all project spaces.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].