threading and atexit: different behaviour in python2.6 from 2.5
Alan
alanwilter at gmail.com
Fri Jun 4 06:01:29 EDT 2010
Hi there,
That's another try to get help about this issue I am facing. To help you to
help me here goes a simple example. This is a very simplification of a very
complex code.
-------------------- thread_ping.py -------------------- begin
import time
import sys
import atexit
from threading import Thread
class testit(Thread):
def __init__ (self,ip):
Thread.__init__(self)
self.ip = ip
self.status = 0
def run(self):
pingaling = os.popen("ping -q -c2 "+self.ip,"r")
while 1:
line = pingaling.readline()
if not line: break
igot = re.findall(testit.lifeline,line)
if igot:
self.status = int(igot[0])
def goodbye(t, report):
print 'Goodbye'
print "Status from ",t.ip,"is",report[t.status]
testit.lifeline = re.compile(r"(\d) packets received")
report = ("No response","Partial Response","Alive")
ip = "209.85.227.104" # www.google.com # try with a failing IP if you want
the test to last a bit longer
t = testit(ip)
atexit.register(goodbye, t, report)
t.start()
exit()
-------------------- thread_ping.py -------------------- end
If one runs like:
amadeus[2579]:~/TMP% time python2.6 thread_ping.py
Goodbye
Status from 209.85.227.104 is Alive
python2.6 thread_ping.py 0.02s user 0.02s system 3% cpu 1.056 total
(i.e., python2.6 wait till the thread finishes and leave... I don't want
this behaviour, see below)
and
amadeus[2580]:~/TMP% time python2.5 thread_ping.py
Goodbye
Status from 209.85.227.104 is No response
python2.5 thread_ping.py 0.01s user 0.01s system 90% cpu 0.030 total
(i.e., python2.5 promptly quit, as desired)
Could someone tell me how to get python2.6 to have the same behaviour I see
with python2.5 for this example code?
Any hint would be very much appreciated indeed.
Many thanks in advance.
Alan
--
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100604/1648e518/attachment.html>
More information about the Python-list
mailing list