Closed relaxedricky closed 2 years ago
I'm having some problems with setting timeouts too, it always goes back to 10.0 seconds. Even if I set every possible timeout higher on connect and init. With a high timeout I could probably do this on a thread.
Which version of the package are you using?
Using the latest version, it should be possible to set a very large timeout.
But note that the timeouts follow a non-decreasing order:
I am using version 0.3.0 it seems:
(droid-Wcv5tG3s) user@coldpi:~/droid$ pip show adb_shell
Name: adb-shell
Version: 0.3.0
I want to be able to run a command in the background though, this is an instance where the app should be run and left running. I don't need to see the output from the app etc, it is a server that I will then use another client to connect to.
I think @atti92 is on the right track with running this shell command in a separate thread. The one thing that might not work about that approach is that, as I recall, all shell commands that this package sends use the same local ID. So I think you could send a shell command with a really long timeout, but I don't think you could send any more shell commands using this package.
I think @atti92 is on the right track with running this shell command in a separate thread. The one thing that might not work about that approach is that, as I recall, all shell commands that this package sends use the same local ID. So I think you could send a shell command with a really long timeout, but I don't think you could send any more shell commands using this package.
I can confirm that if you invoke a long-running blocking command on thread t1
and then attempt to invoke other commands simultaneously on thread t2
, you will get BlockingIOError: [Errno 11] Resource temporarily unavailable
errors. The (short) calls on t2
actually seem to make it through to the device, but it's hard to say what is lost/corrupted so I'd stay away from this strategy.
I thought I'd be able to usenohup
and &
to run the command in the background. I'd like to record the screen while sending other commands, so I tried:
tcpdevice = ... # initialize and connect an AdbDeviceTcp
res = tcpdevice.shell('nohup screenrecord --time-limit 30 /sdcard/myrecording.mp4 &')
This returns immediately (doesn't block), but the device doesn't start recording (/sdcard/myrecording.mp4
never gets created and there's no trace of any screenrecord
in ps
output). res
seems to just be an empty string. Any idea why this approach doesn't work with adb_shell
?
Other potential hacky alternatives:
AdbDeviceTcp
, use subprocess
to call adb
directly to start the background task. Then connect using adb_shell
from this point onwards. (You can't have an open session in adb
and adb_shell
at the same time).tcpdevice.shell('nohup screenrecord --time-limit 30 /sdcard/myrecording.mp4')
(notice no &
) to start the task in thread t1
, then disconnect and reconnect adb_shell
in thread t2
and carry on from there. Downside to this is that it'll result in .recv()
being called on a None
value in t1
. I haven't verified if the process is kept alive on the device, but if nohup
does its job I guess it should be (?).Any other ideas would be greatly appreciated!
Thanks, Janus
Backgrounding a task should be possible with this pull request: https://github.com/JeffLIrion/adb_shell/pull/172
You can install that branch via
pip install https://github.com/JeffLIrion/adb_shell/archive/support-multiple-streams.zip
I think you have two options:
next
on the generator as needed. This should be more efficient. This should be possible using the latest release (0.4.0), as described in my previous comment.
pip install -U adb-shell
Hi @JeffLIrion Is there an example anywhere, or doc, on how to run 2 adb shell commands simultaneously? I'm struggling to find anything, or get anything working. Thanks!
Is their a way to run a task in the following way:
device.shell('su -c "nohup ./bla &"')
and have it go into the background without adb_shell timing out with:
adb_shell.exceptions.TcpTimeoutException: Reading from <IO>:5555 timed out (10.0 seconds)
Thanks