El 08/11/11 23:17, Jose Caballero escribió:
Una solución tonta, pero que igual te sirve, sería convertir el thread
en un daemon. Usando un hilo auxiliar, sería algo así:
import threading
def run_limited(time_limit, thr):
def runwrap():
thr.daemon=True
thr.start()
thr.join(time_limit)
if thr.isAlive():
print "Forzando salida"
t=threading.Thread(target=runwrap)
t.start()
t.join()
class NonStopThread(threading.Thread):
def run(self):
while True:
pass
t=NonStopThread()
run_limited(10,t)
- --
Hyperreals *R: http://ch3m4.org/blog
Quarks, bits y otras criaturas infinitesimales
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJOuyUgAAoJEFdWyBWwhL4FjUgH/1xkp+HtEk2n6IWR0La3Hnig
jHVVbqIME+LBrzQOa8t0yo6oW74azyZxjd3SblwNsRqjopnxszBFxgQzxPZdUDcA
m6byBGVHwCSeTtLSegIhfqgtrYr8MacYrPxALcdcC9j9GYT8ewB038tM2aS7BAHY
ctQK53//R2ZlKt51mSskde/877XeVW8flcKHWCrZ0PvMKiko53ssC/ggzihYr0pp
Hn7gmf+hnGLSimjIlcc9AdQBIcq6I65oPmeHTWH1EKtEMckJLnuFi2BFKas9zuo6
SPreLlat/dJMaged9it0v8yCZsp057YtGGOqCTrJ97kmJ3UwcdkM105/8JjXGOI=
=LPxV
-----END PGP SIGNATURE-----
_______________________________________________
Python-es mailing list
Pyth...@python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/
import threading
def run_limited(time_limit, thr):
def runwrap():
thr.daemon=True
thr.start()
thr.join(time_limit)
if thr.isAlive():
print "Forzando salida"
t=threading.Thread(target=runwrap)
t.start()
t.join()
class NonStopThread(threading.Thread):
def run(self):
while True:
pass
t=NonStopThread()
run_limited(10,t)
El 10/11/2011 17:38, "Jose Caballero" <jcaball...@gmail.com> escribió:
>
Funciona en python2.7 (al menos).
> Pero no en python2.4, que es lo que yo necesito. Mala suerte.
> En python 2.4 veo el mensaje "Forzando salida", pero la ejecucion no se detiene.
Sospecho que en 2.4 está usando la API vieja. Prueba con:
thr.setDaemon(True)