diff options
author | Nathaniel Manista <nathaniel@google.com> | 2017-01-17 15:00:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-17 15:00:34 -0800 |
commit | fc4b07e10c0482522dbc6a01401ea8f1606a76b4 (patch) | |
tree | 622b321c1682d85950c8b9519c2f957b26e6e52e /src/python/grpcio_tests/tests/qps/client_runner.py | |
parent | c0d7d67dfbe4f7d539e64365c4111b748285668f (diff) | |
parent | cc793703bfba6f661f523b6fec82ff8a913e1759 (diff) |
Merge pull request #9276 from soltanmm-google/remember-the-blue-flowers-they-are-important!
Enable yapf (Python formatting).
Diffstat (limited to 'src/python/grpcio_tests/tests/qps/client_runner.py')
-rw-r--r-- | src/python/grpcio_tests/tests/qps/client_runner.py | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/src/python/grpcio_tests/tests/qps/client_runner.py b/src/python/grpcio_tests/tests/qps/client_runner.py index 1fd58687ad..037092313c 100644 --- a/src/python/grpcio_tests/tests/qps/client_runner.py +++ b/src/python/grpcio_tests/tests/qps/client_runner.py @@ -26,7 +26,6 @@ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - """Defines behavior for WHEN clients send requests. Each client exposes a non-blocking send_request() method that the @@ -39,68 +38,68 @@ import time class ClientRunner: - """Abstract interface for sending requests from clients.""" + """Abstract interface for sending requests from clients.""" - __metaclass__ = abc.ABCMeta + __metaclass__ = abc.ABCMeta - def __init__(self, client): - self._client = client + def __init__(self, client): + self._client = client - @abc.abstractmethod - def start(self): - raise NotImplementedError() + @abc.abstractmethod + def start(self): + raise NotImplementedError() - @abc.abstractmethod - def stop(self): - raise NotImplementedError() + @abc.abstractmethod + def stop(self): + raise NotImplementedError() class OpenLoopClientRunner(ClientRunner): - def __init__(self, client, interval_generator): - super(OpenLoopClientRunner, self).__init__(client) - self._is_running = False - self._interval_generator = interval_generator - self._dispatch_thread = threading.Thread( - target=self._dispatch_requests, args=()) - - def start(self): - self._is_running = True - self._client.start() - self._dispatch_thread.start() - - def stop(self): - self._is_running = False - self._client.stop() - self._dispatch_thread.join() - self._client = None - - def _dispatch_requests(self): - while self._is_running: - self._client.send_request() - time.sleep(next(self._interval_generator)) + def __init__(self, client, interval_generator): + super(OpenLoopClientRunner, self).__init__(client) + self._is_running = False + self._interval_generator = interval_generator + self._dispatch_thread = threading.Thread( + target=self._dispatch_requests, args=()) + + def start(self): + self._is_running = True + self._client.start() + self._dispatch_thread.start() + + def stop(self): + self._is_running = False + self._client.stop() + self._dispatch_thread.join() + self._client = None + + def _dispatch_requests(self): + while self._is_running: + self._client.send_request() + time.sleep(next(self._interval_generator)) class ClosedLoopClientRunner(ClientRunner): - def __init__(self, client, request_count): - super(ClosedLoopClientRunner, self).__init__(client) - self._is_running = False - self._request_count = request_count - # Send a new request on each response for closed loop - self._client.add_response_callback(self._send_request) - - def start(self): - self._is_running = True - self._client.start() - for _ in xrange(self._request_count): - self._client.send_request() - - def stop(self): - self._is_running = False - self._client.stop() - self._client = None - - def _send_request(self, client, response_time): - if self._is_running: - client.send_request() + def __init__(self, client, request_count): + super(ClosedLoopClientRunner, self).__init__(client) + self._is_running = False + self._request_count = request_count + # Send a new request on each response for closed loop + self._client.add_response_callback(self._send_request) + + def start(self): + self._is_running = True + self._client.start() + for _ in xrange(self._request_count): + self._client.send_request() + + def stop(self): + self._is_running = False + self._client.stop() + self._client = None + + def _send_request(self, client, response_time): + if self._is_running: + client.send_request() |