def find_in_files(keyword, files, multiline=False,\
                  ignore_case=True, worker_count=WORKER_COUNT):
    """
    @keyword: string
    @files: list of string text file paths
    @ignore_case: boolean
    @multiline: boolean
    @worker_count: int - the number of processes used for parallel searching
    returns a dict where the keys are the path of the files that matched
        and each value is a list of strings (matched sentences)
    """
    if len(files) < 1:
        return {}

    regex = get_regex(keyword)
    try:
        re.compile(regex) # validate it
    except re.error:
        raise re.error('Invalid regex. Make sure your keywords do not have punctuations.')

    results = {}
    pool = Pool(worker_count)
    pool.daemon = True
    workers = []
    for path in files:
        workers.append(pool.apply_async(find_in_file,\
            (path, regex, multiline, ignore_case)\
                                        ))
    for worker in workers:
        res = worker.get()
        if res is not None:
            path, val = res
            results[path] = val
    pool.terminate()
    return results
def find_in_files ( keyword , files , multiline = False , ignore_case = True , worker_count = WORKER_COUNT ) : if len ( files ) < 1 : return { } regex = get_regex ( keyword ) try : re . compile ( regex ) except re . error : raise re . error ( 'Invalid regex. Make sure your keywords do not have punctuations.' ) results = { } pool = Pool ( worker_count ) pool . daemon = True workers = [ ] for path in files : workers . append ( pool . apply_async ( find_in_file , ( path , regex , multiline , ignore_case ) ) ) for worker in workers : res = worker . get ( ) if res is not None : path , val = res results [ path ] = val pool . terminate ( ) return results
@keyword: string
    @files: list of string text file paths
    @ignore_case: boolean
    @multiline: boolean
    @worker_count: int - the number of processes used for parallel searching
    returns a dict where the keys are the path of the files that matched
        and each value is a list of strings (matched sentences)