You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
621 B

import threading
import time
class HiloAbortable(threading.Thread):
def __init__(self):
super(HiloAbortable, self).__init__()
self._abort_event = threading.Event()
def abort(self):
self._abort_event.set()
def aborted(self):
return self._abort_event.is_set()
def run(self):
while (True):
if (self.aborted()):
print ("Hilo abortado")
break
#resto del trabajo a ejecutar
print ("trabajando...")
h =HiloAbortable()
h.start()
time.sleep(1)
print ("Antes de invocación a abort()")
h.abort()
print ("Después de invocación de abort()")

Powered by Informatica FP.