Giter VIP home page Giter VIP logo

pychan's Introduction

Go-style Chan for Python

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

pychan's People

Contributors

stuglaser avatar perlence avatar olegman11 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.