0

Monkeyrunner hangs from time to time.
I am using the following code from the web. (Sorry, I forget the source.)
This code is used to detect the "Monkeyrunner hang issue" and reconnect.

class Timeout():
    """Timeout class using ALARM signal."""
    class Timeout(Exception):
        pass

    def __init__(self, sec):
        self.sec = sec

    def __enter__(self):
        signal.signal(signal.SIGALRM, self.raise_timeout)
        signal.alarm(self.sec)

    def __exit__(self, *args):
        signal.alarm(0)    # disable alarm

    def raise_timeout(self, *args):
        raise Timeout.Timeout()
def snapshot():
    while (True):
        try:
            with Timeout(2):
                return(mdevice().takeSnapshot())
        except Timeout.Timeout:
            print "========================= snapshot timeout ==============="
            mdevice(1)

However, the following error is reported:

  File ".\lib\monkeySetting.py", line 30, in __enter__
    signal.signal(signal.SIGALRM, self.raise_timeout)
AttributeError: 'module' object has no attribute 'SIGALRM'

How can this be solved?
Or is there another way to solve the "Monkeyrunner hang issue"?

Empario
  • 402
  • 6
  • 19

1 Answers1

0

First of all, SIGALRM is not implemented on Windows:

On Windows, signal() can only be called with SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, or SIGTERM. A ValueError will be raised in any other case.

On the other hand, you should try AndroidViewClient/culebra, and I hope you solve the hang problem and don't need SIGALRM at all.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134