1

I use the latest AndroidViewClient version on Windows. After the script clicks on the button next the application connects to the remote server and waiting for a response, during this time there is a like "waiting progress bar" on the screen. The problem is the waiting time is random. I use a while loop waiting for a specific view of a next page screen, similar on this post "Waiting for a specific view on androidviewclient". But if time.sleep() is too short the script hangs forever on the code line vc.dump(), precisely on the code line "received += s.recv(1024)" of this method dump() for ViewServer. There is a watchguard ViewClient.setAlarm(120) but signal.alarm does not work on Windows. Why not using s.settimeout(120) before received += s.recv(1024) and try/except block to prevent a blocking state on Windows ?

Community
  • 1
  • 1
  • For more info, when the script hangs on forever and when the response is finally returned by the remote server, a new page is displayed on screen, I can execute manually the command dump on another terminal and find the specific view I am looking for without any problem, but the running script keeps hanging on and the only way to stop it is to kill it. – tuan dat nguyen Mar 24 '15 at 06:36
  • I'll be glad to merge a patch if you test your solution on Windows (unfortunately I can't do it) and works. – Diego Torres Milano Mar 24 '15 at 20:06
  • Yes, in the method dump() I add a watchguard timeout for any operations on the socket to prevent a blocking state which is available in all platforms. Here are the changes : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(15) – tuan dat nguyen Mar 25 '15 at 07:53
  • while True: if DEBUG_RECEIVED: print >>sys.stderr, " reading from socket..." try: received += s.recv(1024) except Exception, ex: print >> sys.stderr, "ERROR:", ex if doneRE.search(received[-7:]): break The tests on windows are working fine, the socket receiving the data is not blocking anymore. – tuan dat nguyen Mar 25 '15 at 08:04
  • @dtmilano Unfortunately setting socket timeout still has some hanging. I test with another solution, and it looks robust and promising. I use the module eventlet which has defined a timeout and it is threaded. I test and there are no more hanging. I will let the script running 24/24 and will see. Here are below the codes I add in the viewclient.py – tuan dat nguyen Mar 28 '15 at 14:09
  • `import eventlet` `from eventlet import Timeout` ... `def dump(self, window=-1, sleep=1, maxtime=120):` ... `with Timeout(maxtime, False):` `while True:` `if DEBUG_RECEIVED:` `print >>sys.stderr, " reading from socket..."` `received += s.recv(1024)` `eventlet.sleep(0)` `if doneRE.search(received[-7:]):` `break` `s.close()` – tuan dat nguyen Mar 28 '15 at 14:14

1 Answers1

0

I avoided this problem by using timeouts on the function call and retrying in a while loop until it succeeds. See Timeout on a function call for how to use signal.

The following function for waiting for a view based on text works:

import signal

def wait_for_text(vc, text):
    while 1:
        try:
            print('vc dump for text: ' + text)
            signal.alarm(5)
            vc.dump(window=-1, sleep=0)
            signal.alarm(0)
            print('finished: ' + text)
            if vc.findViewWithText(text) is None:
                time.sleep(0.5)
            else:
                return
        except:
            exc_type, exc_value, exc_tb = sys.exc_info()
            print(''.join(trace.format_exception(exc_type, exc_value, exc_tb)))
            time.sleep(0.5)
    raise RuntimeError('Failed waiting '+str(timeout)+'s for text: ' + text)
kyczawon
  • 455
  • 6
  • 14