Merge "Avoid shutting down of a passed executor"
This commit is contained in:
		@@ -203,4 +203,3 @@ class Server(object):
 | 
				
			|||||||
    def stop(self):
 | 
					    def stop(self):
 | 
				
			||||||
        """Stop processing incoming requests."""
 | 
					        """Stop processing incoming requests."""
 | 
				
			||||||
        self._proxy.stop()
 | 
					        self._proxy.stop()
 | 
				
			||||||
        self._executor.shutdown()
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,6 +66,7 @@ class Worker(object):
 | 
				
			|||||||
    def __init__(self, exchange, topic, tasks, executor=None, **kwargs):
 | 
					    def __init__(self, exchange, topic, tasks, executor=None, **kwargs):
 | 
				
			||||||
        self._topic = topic
 | 
					        self._topic = topic
 | 
				
			||||||
        self._executor = executor
 | 
					        self._executor = executor
 | 
				
			||||||
 | 
					        self._owns_executor = False
 | 
				
			||||||
        self._threads_count = -1
 | 
					        self._threads_count = -1
 | 
				
			||||||
        if self._executor is None:
 | 
					        if self._executor is None:
 | 
				
			||||||
            if 'threads_count' in kwargs:
 | 
					            if 'threads_count' in kwargs:
 | 
				
			||||||
@@ -75,6 +76,7 @@ class Worker(object):
 | 
				
			|||||||
            else:
 | 
					            else:
 | 
				
			||||||
                self._threads_count = tu.get_optimal_thread_count()
 | 
					                self._threads_count = tu.get_optimal_thread_count()
 | 
				
			||||||
            self._executor = futures.ThreadPoolExecutor(self._threads_count)
 | 
					            self._executor = futures.ThreadPoolExecutor(self._threads_count)
 | 
				
			||||||
 | 
					            self._owns_executor = True
 | 
				
			||||||
        self._endpoints = self._derive_endpoints(tasks)
 | 
					        self._endpoints = self._derive_endpoints(tasks)
 | 
				
			||||||
        self._server = server.Server(topic, exchange, self._executor,
 | 
					        self._server = server.Server(topic, exchange, self._executor,
 | 
				
			||||||
                                     self._endpoints, **kwargs)
 | 
					                                     self._endpoints, **kwargs)
 | 
				
			||||||
@@ -105,3 +107,5 @@ class Worker(object):
 | 
				
			|||||||
    def stop(self):
 | 
					    def stop(self):
 | 
				
			||||||
        """Stop worker."""
 | 
					        """Stop worker."""
 | 
				
			||||||
        self._server.stop()
 | 
					        self._server.stop()
 | 
				
			||||||
 | 
					        if self._owns_executor:
 | 
				
			||||||
 | 
					            self._executor.shutdown()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -385,7 +385,6 @@ class TestServer(test.MockTestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        # check calls
 | 
					        # check calls
 | 
				
			||||||
        master_mock_calls = [
 | 
					        master_mock_calls = [
 | 
				
			||||||
            mock.call.proxy.stop(),
 | 
					            mock.call.proxy.stop()
 | 
				
			||||||
            mock.call.executor.shutdown()
 | 
					 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
        self.assertEqual(self.master_mock.mock_calls, master_mock_calls)
 | 
					        self.assertEqual(self.master_mock.mock_calls, master_mock_calls)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -132,7 +132,8 @@ class TestWorker(test.MockTestCase):
 | 
				
			|||||||
        self.worker(reset_master_mock=True).stop()
 | 
					        self.worker(reset_master_mock=True).stop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        master_mock_calls = [
 | 
					        master_mock_calls = [
 | 
				
			||||||
            mock.call.server.stop()
 | 
					            mock.call.server.stop(),
 | 
				
			||||||
 | 
					            mock.call.executor.shutdown()
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
        self.assertEqual(self.master_mock.mock_calls, master_mock_calls)
 | 
					        self.assertEqual(self.master_mock.mock_calls, master_mock_calls)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user