From f3cfe4ee2675b97cf31b85954704a221310ccf9a Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 15 Feb 2017 10:58:08 -0500 Subject: [PATCH] Change strategy for stale data protection Rather than assuming a global state, have the generator react to GeneratorExit and clean itself up. --- confluent_client/confluent/client.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index 07a85423..b83050e1 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -27,8 +27,6 @@ import confluent.tlvdata as tlvdata SO_PASSCRED = 16 -inflight = False - def _parseserver(string): if ']:' in string: server, port = string[1:].split(']:') @@ -228,23 +226,19 @@ def send_request(operation, path, server, parameters=None): :param server: The socket to send data over :param parameters: Parameters if any to send along with the request """ - global inflight - if inflight: - # calling code failed to complete a transaction, flush and discard - # their unused data - result = tlvdata.recv(server) - while '_requestdone' not in result: - result = tlvdata.recv(server) - inflight = True payload = {'operation': operation, 'path': path} if parameters is not None: payload['parameters'] = parameters tlvdata.send(server, payload) result = tlvdata.recv(server) while '_requestdone' not in result: - yield result + try: + yield result + except GeneratorExit: + while '_requestdone' not in result: + result = tlvdata.recv(server) + raise result = tlvdata.recv(server) - inflight = False