Skip to content

Commit c65973e

Browse files
committed
Don’t attempt POSIX signal handling on Windows workers
This broke bag validation on Windows when using multiprocessing. Closes #42
1 parent 819508c commit c65973e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

bagit.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,10 @@ def _validate_entries(self, processes):
505505
if not available_hashers:
506506
raise RuntimeError("%s: Unable to validate bag contents: none of the hash algorithms in %s are supported!" % (self, self.algs))
507507

508-
def _init_worker():
509-
signal.signal(signal.SIGINT, signal.SIG_IGN)
508+
if os.name == 'posix':
509+
worker_init = posix_multiprocessing_worker_initializer
510+
else:
511+
worker_init = None
510512

511513
args = ((self.path, rel_path, hashes, available_hashers) for rel_path, hashes in self.entries.items())
512514

@@ -515,7 +517,7 @@ def _init_worker():
515517
hash_results = [_calc_hashes(i) for i in args]
516518
else:
517519
try:
518-
pool = multiprocessing.Pool(processes if processes else None, _init_worker)
520+
pool = multiprocessing.Pool(processes if processes else None, initializer=worker_init)
519521
hash_results = pool.map(_calc_hashes, args)
520522
finally:
521523
try:
@@ -601,6 +603,11 @@ def __str__(self):
601603
return "%s exists on filesystem but is not in manifest" % self.path
602604

603605

606+
def posix_multiprocessing_worker_initializer():
607+
"""Ignore SIGINT in multiprocessing workers on POSIX systems"""
608+
signal.signal(signal.SIGINT, signal.SIG_IGN)
609+
610+
604611
def _calc_hashes(args):
605612
# auto unpacking of sequences illegal in Python3
606613
(base_path, rel_path, hashes, available_hashes) = args

0 commit comments

Comments
 (0)