Avoid shutting down of a passed executor
For the case where an executor is being provided we should not shutdown the executor on-behalf of the provider since they would likely expect that they can still use the executor elsewhere. If the executor is shutdown then further usage is not possible. Change-Id: Ia83d8c2f1df06200e32e9b0c7340f32e74fd5d85
This commit is contained in:
committed by
Stanislav Kudriashev
parent
3b1aab64d2
commit
7607662409
@@ -173,4 +173,3 @@ class Server(object):
|
||||
def stop(self):
|
||||
"""Stop processing incoming requests."""
|
||||
self._proxy.stop()
|
||||
self._executor.shutdown()
|
||||
|
||||
@@ -71,6 +71,7 @@ class Worker(object):
|
||||
def __init__(self, exchange, topic, tasks, executor=None, **kwargs):
|
||||
self._topic = topic
|
||||
self._executor = executor
|
||||
self._owns_executor = False
|
||||
self._threads_count = -1
|
||||
if self._executor is None:
|
||||
if 'threads_count' in kwargs:
|
||||
@@ -80,6 +81,7 @@ class Worker(object):
|
||||
else:
|
||||
self._threads_count = tu.get_optimal_thread_count()
|
||||
self._executor = futures.ThreadPoolExecutor(self._threads_count)
|
||||
self._owns_executor = True
|
||||
self._endpoints = self._derive_endpoints(tasks)
|
||||
self._server = server.Server(topic, exchange, self._executor,
|
||||
self._endpoints, **kwargs)
|
||||
@@ -137,3 +139,5 @@ class Worker(object):
|
||||
def stop(self):
|
||||
"""Stop worker."""
|
||||
self._server.stop()
|
||||
if self._owns_executor:
|
||||
self._executor.shutdown()
|
||||
|
||||
@@ -371,7 +371,6 @@ class TestServer(test.MockTestCase):
|
||||
|
||||
# check calls
|
||||
master_mock_calls = [
|
||||
mock.call.proxy.stop(),
|
||||
mock.call.executor.shutdown()
|
||||
mock.call.proxy.stop()
|
||||
]
|
||||
self.assertEqual(self.master_mock.mock_calls, master_mock_calls)
|
||||
|
||||
@@ -119,7 +119,8 @@ class TestWorker(test.MockTestCase):
|
||||
self.worker(reset_master_mock=True).stop()
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user