Skip to content

Instantly share code, notes, and snippets.

@jaysudodeveloper
Created January 7, 2016 22:33
Show Gist options
  • Save jaysudodeveloper/db92c17dac8e29835222 to your computer and use it in GitHub Desktop.
Save jaysudodeveloper/db92c17dac8e29835222 to your computer and use it in GitHub Desktop.

Revisions

  1. Jay Jamieson created this gist Jan 7, 2016.
    19 changes: 19 additions & 0 deletions test.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # wait for incoming data to consume with a for loop
    def consume():
    while True:
    data = yield
    consumer = data # Aliase the data variable to ensure the generator stays "charged"
    for i in consumer: # consume the data and return back to the while loop
    print i

    # Just a basic generator object for proof of concept
    def in_gen(x):
    for i in range(x):
    yield i

    consumer = consume()
    data = in_gen(5)
    consumer.send(None) # precharge the generator before sending data. this is a must
    # as generator objescts dont start when intantiated

    consumer.send(data)