Skip to main content
Help us improve Python packaging – donate today!

Chan for Python, lovingly stolen from Go

Project Description

Implements Go’s chan type in Python.

Install with pip install chan

Source at http://github.com/stuglaser/pychan

Usage

You can put onto channels, and get from them

c = Chan()

# Thread 1
c.put("Hello")

# Thread 2
print "Heard: %s" % c.get()

Channels can be closed (usually by the sender). Iterating over a channel gives all values until the channel is closed

c = Chan()

# Thread 1
c.put("It's")
c.put("just")
c.put("contradiction")

# Thread 2
for thing in c:
    print "Heard:", thing

You can wait on multiple channels using chanselect. Pass it a list of input channels and another of output channels, and it will return when any of the channels is ready

def fan_in(outchan, input1, input2):
    while True:
        chan, value = chanselect([input1, input2], [])
        if chan == input1:
            outchan.put("From 1: " + str(value))
        else:
            outchan.put("From 2 " + str(value))

You can see more examples in the “examples” directory.

https://nojsstats.appspot.com/UA-41669691-1/github.com

Release history Release notifications

This version
History Node

0.3.1

History Node

0.3.0

History Node

0.2.1

History Node

0.2.0

History Node

0.1.0

History Node

0.1-dev

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
chan-0.3.1.tar.gz (6.5 kB) Copy SHA256 hash SHA256 Source None Nov 24, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page