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