__author__ = 'RMGiroux'

import asyncio
from asyncio import subprocess

class OutputCollector:
    def __init__(self, name):
        self.name = name

    @asyncio.coroutine
    def process_line(self, stream):
        while not stream.at_eof():
            line = yield from stream.readline()
            print("%s: %s"%(name, line))


@asyncio.coroutine
def read_stdout(callback):
    while True:
        line = yield from stdout.readline()
        print('received', repr(line))
        if not line:
            break
        else:
            callback(line)

@asyncio.coroutine
def async_exec(repo, stdoutCallback):
    fork = yield from asyncio.create_subprocess_shell(
        ("git clone %s"%repo),stdout=subprocess.PIPE,stderr=subprocess.STDOUT)

    tasks = []
    if proc.stdout is not None:
        tasks.append(read_stdout(proc.stdout(stdoutCallback)))
    else:
        print('No stdout')

    yield from asyncio.wait(tasks)

    retCode = yield from fork.wait()

    return retCode



@@ -63,16 +63,27 @@
 bprocess
+%0Aimport sys
 %0A%0Aclass 
@@ -375,16 +375,24 @@
 _stdout(
+stream, 
 callback
@@ -438,20 +438,20 @@
  from st
-dout
+ream
 .readlin
@@ -787,20 +787,20 @@
 %0A    if 
-proc
+fork
 .stdout 
@@ -849,20 +849,21 @@
 out(
-proc
+fork
 .stdout
-(
+, 
 stdo
@@ -874,17 +874,16 @@
 llback))
-)
 %0A    els
@@ -1008,8 +1008,174 @@
 tCode%0A%0A%0A
+def test_callback(line):%0A    print(%22Received: %25s%22%25line)%0A%0A%0Aloop = asyncio.get_event_loop()%0A%0Atask = async_exec(sys.argv%5B1%5D, test_callback)%0Aloop.run_until_complete(task)

Fix bugs