Skip to content

Commit 16d4e2b

Browse files
committed
Merge pull request #56 from acdha/42-safe-windows-multiprocessing
Don’t attempt POSIX signal handling on Windows workers
2 parents 4ce3d01 + c65973e commit 16d4e2b

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
@@ -506,8 +506,10 @@ def _validate_entries(self, processes):
506506
if not available_hashers:
507507
raise RuntimeError("%s: Unable to validate bag contents: none of the hash algorithms in %s are supported!" % (self, self.algs))
508508

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

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

@@ -516,7 +518,7 @@ def _init_worker():
516518
hash_results = [_calc_hashes(i) for i in args]
517519
else:
518520
try:
519-
pool = multiprocessing.Pool(processes if processes else None, _init_worker)
521+
pool = multiprocessing.Pool(processes if processes else None, initializer=worker_init)
520522
hash_results = pool.map(_calc_hashes, args)
521523
finally:
522524
try:
@@ -602,6 +604,11 @@ def __str__(self):
602604
return "%s exists on filesystem but is not in manifest" % self.path
603605

604606

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

0 commit comments

Comments
 (0)