1
- from __future__ import absolute_import
1
+ from __future__ import absolute_import , division
2
2
3
3
import collections
4
4
import copy
@@ -491,7 +491,7 @@ def _handle_sasl_handshake_response(self, future, response):
491
491
self .config ['sasl_mechanism' ]))
492
492
493
493
def _send_bytes_blocking (self , data ):
494
- self ._sock .setblocking ( True )
494
+ self ._sock .settimeout ( self . config [ 'request_timeout_ms' ] / 1000 )
495
495
total_sent = 0
496
496
try :
497
497
while total_sent < len (data ):
@@ -501,10 +501,10 @@ def _send_bytes_blocking(self, data):
501
501
raise ConnectionError ('Buffer overrun during socket send' )
502
502
return total_sent
503
503
finally :
504
- self ._sock .setblocking ( False )
504
+ self ._sock .settimeout ( 0.0 )
505
505
506
506
def _recv_bytes_blocking (self , n ):
507
- self ._sock .setblocking ( True )
507
+ self ._sock .settimeout ( self . config [ 'request_timeout_ms' ] / 1000 )
508
508
try :
509
509
data = b''
510
510
while len (data ) < n :
@@ -514,7 +514,7 @@ def _recv_bytes_blocking(self, n):
514
514
data += fragment
515
515
return data
516
516
finally :
517
- self ._sock .setblocking ( False )
517
+ self ._sock .settimeout ( 0.0 )
518
518
519
519
def _try_authenticate_plain (self , future ):
520
520
if self .config ['security_protocol' ] == 'SASL_PLAINTEXT' :
@@ -696,6 +696,7 @@ def _send(self, request):
696
696
# In the future we might manage an internal write buffer
697
697
# and send bytes asynchronously. For now, just block
698
698
# sending each request payload
699
+ sent_time = time .time ()
699
700
total_bytes = self ._send_bytes_blocking (data )
700
701
if self ._sensors :
701
702
self ._sensors .bytes_sent .record (total_bytes )
@@ -707,7 +708,7 @@ def _send(self, request):
707
708
log .debug ('%s Request %d: %s' , self , correlation_id , request )
708
709
709
710
if request .expect_response ():
710
- ifr = (correlation_id , future , time . time () )
711
+ ifr = (correlation_id , future , sent_time )
711
712
self .in_flight_requests .append (ifr )
712
713
else :
713
714
future .success (None )
0 commit comments