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"?