summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2021-12-31 22:02:21 +0100
committerHelmut Grohne <helmut@subdivi.de>2021-12-31 22:02:21 +0100
commit1f99cb38848e22aeb7aec55560a9c559472c63fe (patch)
treebbe63217e67f7a235097d42fa803c18c311f1169
parent083f48a0fc8824f4293b089752a060e3341ba411 (diff)
downloaddebian-dedup-1f99cb38848e22aeb7aec55560a9c559472c63fe.tar.gz
multiarchimport.py: add --sequential option
-rwxr-xr-xmultiarchimport.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/multiarchimport.py b/multiarchimport.py
index 2804612..84eab35 100755
--- a/multiarchimport.py
+++ b/multiarchimport.py
@@ -141,6 +141,19 @@ def consume_items(dct):
except KeyError:
break
+class SequentialPool:
+ """A multiprocessing.Pool replacement that isn't parallel at all."""
+ @staticmethod
+ def apply_async(function, args, callback=None, error_callback=None):
+ try:
+ result = function(*args)
+ except Exception as exception:
+ if error_callback is not None:
+ error_callback(exception)
+ else:
+ if callback is not None:
+ callback(result)
+
def bounded_imap_unordered(bound, pool, function, iterable):
iterable = iter(iterable)
results = queue.Queue()
@@ -190,11 +203,13 @@ def main():
parser.add_argument("-m", "--mirror", action="store",
default="http://deb.debian.org/debian",
help="Debian mirror to use")
+ parser.add_argument("--sequential", action="store_true", default=False,
+ help="avoid using multiple processes or CPUs")
args = parser.parse_args()
architectures = release_architectures(args.mirror)
architectures.add("all")
- workers = multiprocessing.cpu_count()
- pool = multiprocessing.Pool(workers)
+ workers = 1 if args.sequential else multiprocessing.cpu_count()
+ pool = multiprocessing.Pool(workers) if workers > 1 else SequentialPool()
db = sqlite3.connect(args.database)
cur = db.cursor()
cur.execute("PRAGMA foreign_keys = ON;")