@@ -175,7 +175,6 @@ def __init__(self, header, data=''):
175175
176176 def Write (self , usb , timeout_ms = None ):
177177 """Send this message over USB."""
178- timeout_ms = usb .Timeout (timeout_ms )
179178 # We can't merge these 2 writes, the device wouldn't be able to read the
180179 # packet.
181180 try :
@@ -190,7 +189,6 @@ def Read(cls, usb, timeout_ms=None):
190189
191190 Returns None if it failed to read the header with a ReadFailedError.
192191 """
193- timeout_ms = usb .Timeout (timeout_ms )
194192 packet = usb .BulkRead (24 , timeout_ms )
195193 hdr = _AdbMessageHeader .Unpack (packet )
196194 if hdr .data_length :
@@ -228,9 +226,10 @@ def __str__(self):
228226class _AdbConnection (object ):
229227 """One logical ADB connection to a service."""
230228 class _MessageQueue (object ):
231- def __init__ (self , manager ):
229+ def __init__ (self , manager , timeout_ms = None ):
232230 self ._queue = Queue .Queue ()
233231 self ._manager = manager
232+ self ._timeout_ms = timeout_ms
234233
235234 def __iter__ (self ):
236235 return self
@@ -241,7 +240,7 @@ def next(self):
241240 i = self ._queue .get_nowait ()
242241 except Queue .Empty :
243242 # Will reentrantly call self._Add() via parent._OnRead()
244- if not self ._manager .ReadAndDispatch ():
243+ if not self ._manager .ReadAndDispatch (timeout_ms = self . _timeout_ms ):
245244 # Failed to read from the device, the connection likely dropped.
246245 raise StopIteration ()
247246 continue
@@ -255,14 +254,14 @@ def _Add(self, message):
255254 def _Close (self ):
256255 self ._queue .put (StopIteration ())
257256
258- def __init__ (self , manager , local_id , service_name ):
257+ def __init__ (self , manager , local_id , service_name , timeout_ms = None ):
259258 # ID as given by the remote device.
260259 self .remote_id = 0
261260 # Service requested on the remote device.
262261 self .service_name = service_name
263262 # Self assigned local ID.
264263 self ._local_id = local_id
265- self ._yielder = self ._MessageQueue (manager )
264+ self ._yielder = self ._MessageQueue (manager , timeout_ms = timeout_ms )
266265 self ._manager = manager
267266
268267 @property
@@ -423,7 +422,7 @@ def Open(self, destination, timeout_ms=None):
423422 next_id = self ._next_local_id
424423 self ._next_local_id += 1
425424
426- conn = _AdbConnection (self , next_id , destination )
425+ conn = _AdbConnection (self , next_id , destination , timeout_ms = timeout_ms )
427426 conn ._Write ('OPEN' , destination + '\0 ' )
428427 with self ._lock :
429428 self ._connections [conn .local_id ] = conn
0 commit comments