All Projects → pothos → awaitchannel

pothos / awaitchannel

Licence: MIT License
Go-style concurrency and channels with Python 3.5 and asyncio

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to awaitchannel

P Map
Map over promises concurrently
Stars: ✭ 639 (+2942.86%)
Mutual labels:  concurrency, async-await
async-oneshot
A fast, small, full-featured, no-std compatible oneshot channel
Stars: ✭ 55 (+161.9%)
Mutual labels:  concurrency, async-await
Concurrencpp
Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all
Stars: ✭ 340 (+1519.05%)
Mutual labels:  concurrency, async-await
Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+17895.24%)
Mutual labels:  concurrency, async-await
swoole-futures
⏳ Futures, Streams & Async/Await for PHP's Swoole asynchronous run-time.
Stars: ✭ 100 (+376.19%)
Mutual labels:  concurrency, async-await
Ea Async
EA Async implements async-await methods in the JVM.
Stars: ✭ 1,085 (+5066.67%)
Mutual labels:  concurrency, async-await
Asyncio
asyncio historical repository
Stars: ✭ 952 (+4433.33%)
Mutual labels:  concurrency, async-await
async-enumerable-dotnet
Experimental operators for C# 8 IAsyncEnumerables
Stars: ✭ 32 (+52.38%)
Mutual labels:  concurrency, async-await
await-lock
Mutex locks for async functions
Stars: ✭ 66 (+214.29%)
Mutual labels:  concurrency, async-await
conquerant
lightweight async/await for Clojure
Stars: ✭ 31 (+47.62%)
Mutual labels:  concurrency, async-await
Shift
Light-weight EventKit wrapper.
Stars: ✭ 31 (+47.62%)
Mutual labels:  concurrency, async-await
mux-stream
(De)multiplex asynchronous streams
Stars: ✭ 34 (+61.9%)
Mutual labels:  concurrency, async-await
drone-cortexm
ARM® Cortex®-M platform crate for Drone, an Embedded Operating System.
Stars: ✭ 31 (+47.62%)
Mutual labels:  concurrency
concurrency-kit
🚄 Concurrency abstractions framework for Apple Platforms [Task, Atomic, Lock, Operation, etc.].
Stars: ✭ 17 (-19.05%)
Mutual labels:  concurrency
awesome-dotnet-async
A curated list of awesome articles and resources to learning and practicing about async, threading, and channels in .Net platform. 😉
Stars: ✭ 84 (+300%)
Mutual labels:  async-await
Sworm
CoreData based Swift ORM
Stars: ✭ 70 (+233.33%)
Mutual labels:  concurrency
trading sim
📈📆 Backtest trading strategies concurrently using historical chart data from various financial exchanges.
Stars: ✭ 21 (+0%)
Mutual labels:  concurrency
kbio
Another Async IO Framework based on io_uring
Stars: ✭ 54 (+157.14%)
Mutual labels:  async-await
hano-graphql
GraphQL, Hapi and Node Project For Scaleable Apps.
Stars: ✭ 13 (-38.1%)
Mutual labels:  async-await
piker
#nontina, #paperhands,, #pwnzebotz, #tradezbyguille
Stars: ✭ 63 (+200%)
Mutual labels:  concurrency

awaitchannel

Go-style concurrency and channels with Python 3.5 and asyncio

Extends the synchronisation objects of asyncio (e.g. Lock, Event, Condition, Semaphore, Queue) with Channels like in Go. Channels can be used for asynchronous or synchronous message exchange. select() can be used to react on finished await-calls and thus also on sending or receiving with channels. The helper go() provides a simple way to schedule the concurrent functions in an event loop of a different thread.

from awaitchannel import Chan, select, go, ChannelClosed, loop

c = Chan()  # synchronous communication

async def give(v):
  for i in range(0, 10):
    await c.send(v + str(i))

async def consume(ID):
  async for v in c:
    print(ID, 'got', v)

go(consume, 'A')
go(consume, 'B')
r1 = go(give, 'x')
go(consume, 'C')
r2 = go(give, 'y')
# …
r1.result()  # wait for sending to be complete
r2.result()
go(c.close)  # cleanup pending consume iters of 'async for' (i.e. await c.recv)

Chan(size=0): Go-style channel with await send/recv, can also be used as an iterator which is calling recv() until a ChannelClosed exception occurs, size 0 indicates a synchronous channel (handshake), size -1 indicates an unlimited buffer size, otherwise send will block when buffer size is reached

@asyncio.coroutine chan.close() closes the channel which leads to a failure at the recv side if empty and disallows further sending,

@asyncio.coroutine chan.send(item) async-blocks if size=0 until there is a recv and this send operation was chosen, blocks if send was used times without a recv, blocks never for size=-1,

chan.send_ready() and .recv_ready() are non-blocking testers,

@asyncio.coroutine chan.recv() async-blocks until something is available and fails if channel is closed after all is processed

@asyncio.coroutine select(futures_list): parameter: select on a list of identifier-await-tuples like ['r', c.recv()), (c, c.send(2))]

Returns a tuple consiting of an identifier-result-tuple like ('r', 7) or (c, None) and a special list object of pending tasks which can be directly used for the next select call or even expanded/appended on before. Be aware that the results are internally buffered when more complete at the same time and thus the logical ordering can be different.

g(f, *args, **kwargs): schedule an async function on the asyncio event loop of the worker thread

Returns a concurrent.future which has a (non-await, but normal) blocking .result() method to wait until the result of f() is returned.

To run a blocking function in a background thread and get an awaitable future for it, use the run_in_executor method of the loop:

f = loop.run_in_executor(None, normal_longrunning_function)
res = await f

Note that you need to pass the .loop attribute of this module when you are using functions provided by asyncio yourself.

Run an example:

PYTHONPATH=. examples/sieve.py
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].