def run_threads(): jobs = [] path = os.path.join(os.getcwd(), 'texts') pattern = re.compile(r'\w{4}') texts = list_texts(path) for text in texts: thread = threading.Thread(target=find_pattern, args=(pattern, text)) jobs.append(thread) for j in jobs: j.start() for j in jobs: j.join()
def send_queue(text, q): title, freqs = getTitleFreqs(text, 1) q.put((title, freqs)) def shared_dict(text, container): title, freqs = getTitleFreqs(text, 1) container[title] = freqs def freqsPerText(text): title, freqs = getTitleFreqs(text, 1) return (title, freqs) texts = list_texts(os.path.join(os.getcwd(), "texts")) def multiprocess_pipe(): jobs = [] parent_conn, child_conn = Pipe() for text in texts: process = Process(target=send_pipe, args=(text, child_conn)) jobs.append(process) for j in jobs: j.start() for j in jobs: j.join()