mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	bpo-30775: Fix refleaks in test_multiprocessing (#2467)
Forgetting to call Process.join() can keep some resources alive.
This commit is contained in:
		
							parent
							
								
									ccdc09ed1e
								
							
						
					
					
						commit
						a79f8faccf
					
				
					 1 changed files with 17 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -1253,10 +1253,19 @@ def __init__(self, namespace, f, args, n, wait_before_exit=False):
 | 
			
		|||
        self._can_exit = namespace.Event()
 | 
			
		||||
        if not wait_before_exit:
 | 
			
		||||
            self._can_exit.set()
 | 
			
		||||
 | 
			
		||||
        threads = []
 | 
			
		||||
        for i in range(n):
 | 
			
		||||
            p = namespace.Process(target=self.task)
 | 
			
		||||
            p.daemon = True
 | 
			
		||||
            p.start()
 | 
			
		||||
            threads.append(p)
 | 
			
		||||
 | 
			
		||||
        def finalize(threads):
 | 
			
		||||
            for p in threads:
 | 
			
		||||
                p.join()
 | 
			
		||||
 | 
			
		||||
        self._finalizer = weakref.finalize(self, finalize, threads)
 | 
			
		||||
 | 
			
		||||
    def task(self):
 | 
			
		||||
        pid = os.getpid()
 | 
			
		||||
| 
						 | 
				
			
			@ -1279,6 +1288,9 @@ def wait_for_finished(self):
 | 
			
		|||
    def do_finish(self):
 | 
			
		||||
        self._can_exit.set()
 | 
			
		||||
 | 
			
		||||
    def close(self):
 | 
			
		||||
        self._finalizer()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AppendTrue(object):
 | 
			
		||||
    def __init__(self, obj):
 | 
			
		||||
| 
						 | 
				
			
			@ -1311,8 +1323,11 @@ def DummyList(self):
 | 
			
		|||
 | 
			
		||||
    def run_threads(self, f, args):
 | 
			
		||||
        b = Bunch(self, f, args, self.N-1)
 | 
			
		||||
        f(*args)
 | 
			
		||||
        b.wait_for_finished()
 | 
			
		||||
        try:
 | 
			
		||||
            f(*args)
 | 
			
		||||
            b.wait_for_finished()
 | 
			
		||||
        finally:
 | 
			
		||||
            b.close()
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def multipass(cls, barrier, results, n):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue