*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit c2895dbd authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

Interpret negative thread count as subtrahend from reported CPU count

parent 5472dc2c
No related branches found
No related tags found
1 merge request!11Add pickle as an output file format for formatscaper
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import argparse import argparse
import dataclasses import dataclasses
import os
import pickle import pickle
import re import re
import subprocess import subprocess
...@@ -59,7 +60,7 @@ parser.add_argument( ...@@ -59,7 +60,7 @@ parser.add_argument(
"-p", "-p",
default=1, default=1,
type=int, type=int,
help="number of siegfried processes to run in parallel (default: 1)", help="number of siegfried processes to run in parallel; 0 and negative numbers will subtract from the number of CPU cores (default: 1)", # noqa
) )
parser.add_argument( parser.add_argument(
"--sf-binary", "--sf-binary",
...@@ -137,10 +138,30 @@ except OSError as e: ...@@ -137,10 +138,30 @@ except OSError as e:
sf_error_log = None sf_error_log = None
# determine the level of threads to run in parallel
# negative numbers mean "this much less than the number of CPUs I have",
# as long as the result is greater than 0
if (num_threads := args.parallel) <= 0:
num_cores = os.cpu_count()
if num_cores is None:
num_threads = 1
print(
"WARN: couldn't determine number of CPU cores, falling back to a single thread", # noqa
file=sys.stderr,
)
else:
num_threads = os.cpu_count() + num_threads
if num_threads <= 0:
print(
f"ERROR: calculated number of threads would be less than 1: {num_threads}", # noqa
file=sys.stderr,
)
sys.exit(1)
# set up variables required in the collection of results # set up variables required in the collection of results
all_results = [] all_results = []
endangered_files = [] endangered_files = []
sem = threading.Semaphore(args.parallel) sem = threading.Semaphore(num_threads)
mutex = threading.Lock() mutex = threading.Lock()
completed_tasks = 0 completed_tasks = 0
progress_bar = progressbar.ProgressBar( progress_bar = progressbar.ProgressBar(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment