Skip to content

Instantly share code, notes, and snippets.

@gthank
Created January 21, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gthank/ff0236e078aabb1b6dbb to your computer and use it in GitHub Desktop.
Save gthank/ff0236e078aabb1b6dbb to your computer and use it in GitHub Desktop.
with ThreadPoolExecutor(max_workers=5) as executor:
metadata_by_future = {}
csv_files = args["CSV-FILE"]
for csv_file in csv_files:
try:
metadata = _preprocess_csv(csv_file, in_progress_dir,
processed_dir)
future = executor.submit(process_csv, uri, metadata)
metadata_by_future[future] = metadata
except Exception:
log.exception("unexpected exception: failed to process <%s>",
csv_file)
failure_log.error(csv_file)
print("OK, what?")
for f in as_completed(metadata_by_future):
metadata = metadata_by_future[f]
try:
handle_response(f.result(timeout=10), metadata)
except Exception:
log.exception("unexpected exception: failed to process <%s>",
csv_file)
_log_permanent_failure(metadata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment