So I am trying to include a way to force a function in my app to time out and terminate gracefully if it doesn't return in a given amount of time. I'm hoping there is a way to do this easily that I am just overlooking. I examined the Clock module of kivy, but it looked like most of the function args named 'timeout' were just telling the Clock how far out to schedule the function call.
What I am currently doing that works on my computer, but not on Android, is using the python multiprocess module and its Pool class. So I have something like
# Just a single worker process
pool = Pool(1)
result = pool.apply_async(myfunc)
timeout = 20.0
try:
res = result.get(timeout=timeout)
...
except TimeoutError as e:
print "Took longer than 20 seconds in the function, aborting!"
pool.close()
My problem is that even after fiddling with getting the multiprocessing library into my app distribution, it turns out that the Android OS has a broken implementation of semaphores (that's what the error message led me to believe at least).
The function that can take such a long time is from Sympy, and it usually means it won't be returning meaningful results anyway. If there is a way to handle this kind of interrupt by modifying the actual function that would be fine with me too since I have access to the source.
Thanks in advance, and any help or guidance would be much appreciated!