diff options
| author | jvoisin | 2022-03-29 22:15:04 +0200 |
|---|---|---|
| committer | jvoisin | 2022-03-29 22:15:04 +0200 |
| commit | 1b37604d3a5b9af1a776ed73bcc18eacf597394e (patch) | |
| tree | 9681d85c52e0d1bac9497e6a996cc110057ad0b0 | |
| parent | 1c3e2afa1e4fa39b21677932558cd14a21a990b4 (diff) | |
Make processing multiple files safer concurrence-wise
| -rwxr-xr-x | mat2 | 6 |
1 files changed, 3 insertions, 3 deletions
| @@ -221,14 +221,14 @@ def main() -> int: | |||
| 221 | files = __get_files_recursively(args.files) | 221 | files = __get_files_recursively(args.files) |
| 222 | # We have to use Processes instead of Threads, since | 222 | # We have to use Processes instead of Threads, since |
| 223 | # we're using tempfile.mkdtemp, which isn't thread-safe. | 223 | # we're using tempfile.mkdtemp, which isn't thread-safe. |
| 224 | futures = list() | ||
| 224 | with concurrent.futures.ProcessPoolExecutor() as executor: | 225 | with concurrent.futures.ProcessPoolExecutor() as executor: |
| 225 | futures = list() | ||
| 226 | for f in files: | 226 | for f in files: |
| 227 | future = executor.submit(clean_meta, f, args.lightweight, | 227 | future = executor.submit(clean_meta, f, args.lightweight, |
| 228 | inplace, args.sandbox, policy) | 228 | inplace, args.sandbox, policy) |
| 229 | futures.append(future) | 229 | futures.append(future) |
| 230 | for future in concurrent.futures.as_completed(futures): | 230 | for future in concurrent.futures.as_completed(futures): |
| 231 | no_failure &= future.result() | 231 | no_failure &= future.result() |
| 232 | return 0 if no_failure is True else -1 | 232 | return 0 if no_failure is True else -1 |
| 233 | 233 | ||
| 234 | 234 | ||
