@@ -53,6 +53,9 @@ def isSet():
53
53
# Some global variables we use
54
54
DEBUG = False
55
55
_GLOBAL_DEFAULT_TIMEOUT = object ()
56
+ PY25PLUS = sys .version_info [:2 ] >= (2 , 5 )
57
+ PY26PLUS = sys .version_info [:2 ] >= (2 , 6 )
58
+ PY32PLUS = sys .version_info [:2 ] >= (3 , 2 )
56
59
57
60
# Begin import game to handle Python 2 and Python 3
58
61
try :
@@ -64,14 +67,15 @@ def isSet():
64
67
json = None
65
68
66
69
try :
67
- import xml .etree .cElementTree as ET
68
- except ImportError :
70
+ import xml .etree .ElementTree as ET
69
71
try :
70
- import xml .etree .ElementTree as ET
72
+ from xml .etree .ElementTree import _Element as ET_Element
71
73
except ImportError :
72
- from xml .dom import minidom as DOM
73
- from xml .parsers .expat import ExpatError
74
- ET = None
74
+ pass
75
+ except ImportError :
76
+ from xml .dom import minidom as DOM
77
+ from xml .parsers .expat import ExpatError
78
+ ET = None
75
79
76
80
try :
77
81
from urllib2 import (urlopen , Request , HTTPError , URLError ,
@@ -262,6 +266,16 @@ def write(data):
262
266
write (arg )
263
267
write (end )
264
268
269
+ if PY32PLUS :
270
+ etree_iter = ET .Element .iter
271
+ elif PY25PLUS :
272
+ etree_iter = ET_Element .getiterator
273
+
274
+ if PY26PLUS :
275
+ thread_is_alive = threading .Thread .is_alive
276
+ else :
277
+ thread_is_alive = threading .Thread .isAlive
278
+
265
279
266
280
# Exception "constants" to support Python 2 through Python 3
267
281
try :
@@ -1262,7 +1276,7 @@ def get_servers(self, servers=None, exclude=None):
1262
1276
raise SpeedtestServersError (
1263
1277
'Malformed speedtest.net server list: %s' % e
1264
1278
)
1265
- elements = root . getiterator ( 'server' )
1279
+ elements = etree_iter ( root , 'server' )
1266
1280
except AttributeError :
1267
1281
try :
1268
1282
root = DOM .parseString (serversxml )
@@ -1499,9 +1513,10 @@ def producer(q, requests, request_count):
1499
1513
finished = []
1500
1514
1501
1515
def consumer (q , request_count ):
1516
+ _is_alive = thread_is_alive
1502
1517
while len (finished ) < request_count :
1503
1518
thread = q .get (True )
1504
- while thread . isAlive ( ):
1519
+ while _is_alive ( thread ):
1505
1520
thread .join (timeout = 0.1 )
1506
1521
finished .append (sum (thread .result ))
1507
1522
callback (thread .i , request_count , end = True )
@@ -1514,9 +1529,10 @@ def consumer(q, request_count):
1514
1529
start = timeit .default_timer ()
1515
1530
prod_thread .start ()
1516
1531
cons_thread .start ()
1517
- while prod_thread .isAlive ():
1532
+ _is_alive = thread_is_alive
1533
+ while _is_alive (prod_thread ):
1518
1534
prod_thread .join (timeout = 0.1 )
1519
- while cons_thread . isAlive ( ):
1535
+ while _is_alive ( cons_thread ):
1520
1536
cons_thread .join (timeout = 0.1 )
1521
1537
1522
1538
stop = timeit .default_timer ()
@@ -1584,9 +1600,10 @@ def producer(q, requests, request_count):
1584
1600
finished = []
1585
1601
1586
1602
def consumer (q , request_count ):
1603
+ _is_alive = thread_is_alive
1587
1604
while len (finished ) < request_count :
1588
1605
thread = q .get (True )
1589
- while thread . isAlive ( ):
1606
+ while _is_alive ( thread ):
1590
1607
thread .join (timeout = 0.1 )
1591
1608
finished .append (thread .result )
1592
1609
callback (thread .i , request_count , end = True )
@@ -1599,9 +1616,10 @@ def consumer(q, request_count):
1599
1616
start = timeit .default_timer ()
1600
1617
prod_thread .start ()
1601
1618
cons_thread .start ()
1602
- while prod_thread .isAlive ():
1619
+ _is_alive = thread_is_alive
1620
+ while _is_alive (prod_thread ):
1603
1621
prod_thread .join (timeout = 0.1 )
1604
- while cons_thread . isAlive ( ):
1622
+ while _is_alive ( cons_thread ):
1605
1623
cons_thread .join (timeout = 0.1 )
1606
1624
1607
1625
stop = timeit .default_timer ()
0 commit comments