@@ -506,8 +506,10 @@ def _validate_entries(self, processes):
506
506
if not available_hashers :
507
507
raise RuntimeError ("%s: Unable to validate bag contents: none of the hash algorithms in %s are supported!" % (self , self .algs ))
508
508
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
511
513
512
514
args = ((self .path , rel_path , hashes , available_hashers ) for rel_path , hashes in self .entries .items ())
513
515
@@ -516,7 +518,7 @@ def _init_worker():
516
518
hash_results = [_calc_hashes (i ) for i in args ]
517
519
else :
518
520
try :
519
- pool = multiprocessing .Pool (processes if processes else None , _init_worker )
521
+ pool = multiprocessing .Pool (processes if processes else None , initializer = worker_init )
520
522
hash_results = pool .map (_calc_hashes , args )
521
523
finally :
522
524
try :
@@ -602,6 +604,11 @@ def __str__(self):
602
604
return "%s exists on filesystem but is not in manifest" % self .path
603
605
604
606
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
+
605
612
def _calc_hashes (args ):
606
613
# auto unpacking of sequences illegal in Python3
607
614
(base_path , rel_path , hashes , available_hashes ) = args
0 commit comments