diff options
-rwxr-xr-x | multiarchimport.py | 19 |
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;") |