Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

[![Build Status](https://travis-ci.org/tbug/aiochannel.svg?branch=master)](https://travis-ci.org/tbug/aiochannel)

aiochannel - AsyncIO Channel
============================

Channel concept for asyncio.

*requires* Python 3.4.4+ (I think)


Usage
-----------

### Basics

Channels are 90% `asyncio.Queue`, and the API is very similar.
The key difference is that a channel is only considered "done"
when it has been both closed and drained, so calling `.join()`
on a channel will wait for it to be both closed and drained
(Unlike `Queue` which will return from `.join()` once the queue
is empty).

*NOTE* Closing a channel is permanent. You cannot open it again.

```py

import asyncio
from aiochannel import Channel

# ...

# A Channel takes a max queue size and an loop
# both optional
my_channel = Channel(100, asyncio.get_event_loop())

# You add items to the channel with
yield from my_channel.put("my item")
# Note that this can throw ChannelClosed if the channel
# is closed, during the attempt at adding the item
# to the channel. Also note that .put() will block until
# it can successfully add the item.


# Retrieving is done with
my_item = yield from my_channel.get()
# Note that this can also throw ChannelClosed if the
# channel is closed before or during retrival.
# .get() will block until an item can be retrieved.


# You can wait for the channel to be closed and drained:
yield from my_channel.join()
# Note that this requires someone else to close and drain
# the channel.

# Lastly, you can close a channel with
my_channel.close()
# Every call to .put() after .close() will fail with
# a ChannelClosed.
# you can check if a channel is marked for closing with
if my_channel.closed():
print ("Channel is closed")
```

Like the `asyncio.Queue` you can also call non-coroutine get and put:

```py

# non-coroutine version of put
my_channel.put_nowait(item)
# This either returns None,
# or raises ChannelClosed or ChannelFull

# non-coroutine version of get
my_channel.get_nowait()
# This either returns the next item from the channel
# or raises ChannelEmpty or ChannelClosed
# (Note that ChannelClosed emplies that the channel
# is empty, but also that is will never fill again)
```

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

aiochannel-0.0.4.dev0.zip (13.2 kB view details)

Uploaded Source

aiochannel-0.0.4.dev0.tar.gz (7.5 kB view details)

Uploaded Source

File details

Details for the file aiochannel-0.0.4.dev0.zip.

File metadata

  • Download URL: aiochannel-0.0.4.dev0.zip
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiochannel-0.0.4.dev0.zip
Algorithm Hash digest
SHA256 95ec8065335ac487b5b73bc298b7ce367b63a1031eba8d303ebe49d56a4607d6
MD5 491c2245bf976422da9d3da3adb8718f
BLAKE2b-256 b3480776ec0133a61ced7f8408af4d280db8a9d4fc2857cb6b28e19e6beb081c

See more details on using hashes here.

File details

Details for the file aiochannel-0.0.4.dev0.tar.gz.

File metadata

File hashes

Hashes for aiochannel-0.0.4.dev0.tar.gz
Algorithm Hash digest
SHA256 5e52229bc31b89b70312ccdeae576d8db2f29a09464cde40dad7f0e3e5bb296e
MD5 851d343caf5c2fe15345c9e5ece2bff0
BLAKE2b-256 4aa14553f2c42467badc1af943bd9f2071564a39b2d5c3e2dd1295e693e7667b

See more details on using hashes here.

Release history Release notifications | RSS feed

1.4.1

2 files

1.4.0

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.1.1

1 file

1.0.1

1 file

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

This release

0.0.4.dev0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page