[pyar] Ejecutando procesos.
Esteban Kuber
ekuber en gmail.com
Vie Ago 13 19:24:50 ART 2010
> Un ejemplo ? :D
http://stackoverflow.com/questions/492519/timeout-on-a-python-function-call/492644#492644
def timeout(func, args=(), kwargs={}, timeout_duration=10, default=None):
"""This function will spawn a thread and run the given function
using the args, kwargs and return the given default value if the
timeout_duration is exceeded.
"""
import threading
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.result = default
def run(self):
self.result = func(*args, **kwargs)
it = InterruptableThread()
it.start()
it.join(timeout_duration)
if it.isAlive():
return it.result
else:
return it.result
More information about the pyar
mailing list