Closed jvmk closed 3 years ago
I admit that the timeouts are confusing, I'll see if I can clean that up. But I don't think this is a bug...
Also note that the hack seems to fail if the user modifies
adb_shell.constants.DEFAULT_READ_TIMEOUT_S
First of all, you shouldn't modify that -- it's supposed to be a constant, hence the constants.py
module and the all caps name.
Second, I think you would need to modify adb_shell.adb_device.constants.DEFAULT_READ_TIMEOUT_S
due to the way the imports are performed. But again, you shouldn't do this.
But most of all, you shouldn't need this workaround in the first place. Try providing all three timeout parameters to the shell()
method and see if that fixes the problem. You can use the same value for all three.
FYI:
This device is rather resource constrained and is in some instances rather slow at responding to ADB commands (including when using the ADB binary directly, not involving
adb_shell
)
Hi Jeff,
I admit that the timeouts are confusing, I'll see if I can clean that up. But I don't think this is a bug...
Yes, it might just be that I misunderstood what timeout values are supposed to trump others :). I (incorrectly?) assumed that the timeouts provided to the
AdbDeviceTcp
constructor and/or theconnect()
call would apply for.shell()
calls if I omitted the timeout parameters when calling.shell()
.Also note that the hack seems to fail if the user modifies
adb_shell.constants.DEFAULT_READ_TIMEOUT_S
First of all, you shouldn't modify that -- it's supposed to be a constant, hence the
constants.py
module and the all caps name.Second, I think you would need to modify
adb_shell.adb_device.constants.DEFAULT_READ_TIMEOUT_S
due to the way the imports are performed. But again, you shouldn't do this.
Yes, I realize I shouldn't be modifying these constants. I did this as a last resort because I didn't understand why the timeout I specified in the AdbDeviceTcp
constructor and connect()
call didn't come into effect.
But most of all, you shouldn't need this workaround in the first place. Try providing all three timeout parameters to the
shell()
method and see if that fixes the problem. You can use the same value for all three.
Makes sense, I'll try this out, cheers.
Thanks again, Janus
Try providing all three timeout parameters to the
shell()
method and see if that fixes the problem. You can use the same value for all three.
Did that work?
Try providing all three timeout parameters to the
shell()
method and see if that fixes the problem. You can use the same value for all three.Did that work?
Hi Jeff,
Yes, I just verified that if I set all 3 timeouts in .shell()
to 4.0, the timeout does become 4.0 seconds as expected:
adb_shell.exceptions.TcpTimeoutException: Reading from <IP>:<PORT> timed out (4.0 seconds)
Thanks for guiding me to a cleaner solution!
Best, Janus
Description
Hi Jeff,
Great tool, thanks a ton for making it available!
I'm having trouble specifying custom timeouts. It seems that a call to
AdbDeviceTcp.shell()
uses/propagates the timeout values provided as arguments toAdbDeviceTcp.shell()
even when these parameters are omitted. This results in timeout values provided to theAdbDeviceTcp
constructor being overwritten. I'm not sure if this is intentional (I assume not), or if I am using the API wrong.For example:
Using code similar to the example above (multiple calls to
AdbDeviceTcp.shell()
, although not just uninstall commands), I occasionally getTcpTimeoutException
s with a message indicating that the (read) timeout was 10 seconds (the default value) rather than the expected 60 seconds (the value I provided in theAdbDeviceTcp
constructor and inAdbDeviceTcp.connect()
, although the latter may be unrelated as that's a transport timeout):Platform details (in case it matters)
I'm using
adb_shell
to control a Fire TV Stick with Alexa Voice Remote (i.e., Fire TV Stick 2nd generation that was reissued early 2019), that runs Fire OS 5 which is based on Android 5.1 (I'm on Fire OS 5.2.7.7 to be exact). This device is rather resource constrained and is in some instances rather slow at responding to ADB commands (including when using the ADB binary directly, not involvingadb_shell
), thus the default timeout is simply too strict for this particular device.I'm using the latest
adb_shell
release:Full stack trace
An example of the full stack trace (I replaced local paths and IP addresses with placeholders):
Workaround
I've found a hacky workaround that seems to solve the issue for me for now. I manually modified
/home/username/python_venvs/some_venv/lib/python3.7/site-packages/adb_shell/adb_device.py
, adding the highlighted block of code toAdbDevice.shell()
:This is probably not the right place for this change - I went with the most straightforward solution that seemed to fit my needs. I'm guessing it should probably go in the
AdbDeviceTcp
subclass s.t. you don't have to do type checks, but I don't understand the codebase well enough to be the judge of that. Also note that the hack seems to fail if the user modifiesadb_shell.constants.DEFAULT_READ_TIMEOUT_S
, e.g., something like this:If I recall correctly,
AdbDeviceTcp.shell()
still gets called withread_timeout_s=10
for this scenario, which makes theif read_timeout_s == constants.DEFAULT_READ_TIMEOUT_S and ...
check in the hack above false asconstants.DEFAULT_READ_TIMEOUT_S == 60.0
.Once again thanks for providing a great, well-documented tool.
Best, Janus