<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def grep(query, directory):
 """This function will search through the directory structure of the application and for each directory it finds it launches an Async task to run itself. For each .py file it finds, it actually greps the file and then returns the found output."""


    dir_contents = os.listdir(directory)
    results = []
    for item in dir_contents:
        path = os.path.join(directory, item)
        if os.path.isdir(path):
            build_and_start(query, path)
        else:
            if item.endswith('.py'):
                results.extend(grep_file(query, path))
    return results