1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| with ProcessPoolExecutor(max_workers=max_workers) as executor: futures = [] for d in data: args = (d, CONTENT) futures.append(executor.submit(process_record, args))
for idx, future in enumerate(tqdm.tqdm(as_completed(futures), total=len(futures), desc="Extracting info")): result = future.result() new_data.append(result)
if (idx + 1) % 500 == 0: with open(save_path, "w", encoding="utf-8") as f: json.dump(new_data, f, indent=4, ensure_ascii=False) print(f"Extracted information from {idx+1} medical records, and saved to {save_path}")
|