I'm doing a python 2.7 plugin that perform some tests on android devices.
One of my test use an adb command, but this command is doing an infinite loop on some devices.
command: adb shell am start -W -a android.intent.action.VOICE_COMMAND
expected output:
Starting: Intent { act=android.intent.action.VOICE_COMMAND }
Status: ok
Activity: com.google.android.googlequicksearchbox/com.google.android.apps.gsa.velour.dynamichosts.TransparentVelvetDynamicHostActivity
ThisTime: 241
TotalTime: 659
WaitTime: 684
Complete
On most of my devices this command work well but on other it loop and never return something.
I tryed to call this command into a thread, but even doing this I can't figure out how to kill that thread after a timeout.
Here is what I have already tryed (see this) but none of these work because the thread is locked into that infinite loop call and so I can't check if an "end" variable is set into this thread, nor handle event.
Is there a way to kill this Thread after a certain amount of time with something like this ? =>
endtime = time.time() + 20
t1 = MyThread(my_func, "my_args", "my_args2")
while True:
if time.time() > endtime:
end_thread(t1) # or t1.end() or idk
else:
time.sleep(1)