Skip to content

Commit 81bba60

Browse files
authored
Add support for py38 without deprecation warnings (#585)
* Add support for py38 without deprecation warnings * Address Py2.5 issue * Add py3.7 and 3.8 * xenial * pypy trusty
1 parent 681cdf2 commit 81bba60

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
language: python
2+
sudo: required
3+
dist: xenial
24

35
addons:
46
apt:
@@ -33,8 +35,13 @@ matrix:
3335
env: TOXENV=py35
3436
- python: 3.6
3537
env: TOXENV=py36
38+
- python: 3.7
39+
env: TOXENV=py37
40+
- python: 3.8-dev
41+
env: TOXENV=py38
3642
- python: pypy
3743
env: TOXENV=pypy
44+
dist: trusty
3845

3946
before_install:
4047
- if [[ $(echo "$TOXENV" | egrep -c "py35") != 0 ]]; then pyenv global system 3.5; fi;

speedtest.py

+31-13
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def isSet():
5353
# Some global variables we use
5454
DEBUG = False
5555
_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)
5659

5760
# Begin import game to handle Python 2 and Python 3
5861
try:
@@ -64,14 +67,15 @@ def isSet():
6467
json = None
6568

6669
try:
67-
import xml.etree.cElementTree as ET
68-
except ImportError:
70+
import xml.etree.ElementTree as ET
6971
try:
70-
import xml.etree.ElementTree as ET
72+
from xml.etree.ElementTree import _Element as ET_Element
7173
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
7579

7680
try:
7781
from urllib2 import (urlopen, Request, HTTPError, URLError,
@@ -262,6 +266,16 @@ def write(data):
262266
write(arg)
263267
write(end)
264268

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+
265279

266280
# Exception "constants" to support Python 2 through Python 3
267281
try:
@@ -1262,7 +1276,7 @@ def get_servers(self, servers=None, exclude=None):
12621276
raise SpeedtestServersError(
12631277
'Malformed speedtest.net server list: %s' % e
12641278
)
1265-
elements = root.getiterator('server')
1279+
elements = etree_iter(root, 'server')
12661280
except AttributeError:
12671281
try:
12681282
root = DOM.parseString(serversxml)
@@ -1499,9 +1513,10 @@ def producer(q, requests, request_count):
14991513
finished = []
15001514

15011515
def consumer(q, request_count):
1516+
_is_alive = thread_is_alive
15021517
while len(finished) < request_count:
15031518
thread = q.get(True)
1504-
while thread.isAlive():
1519+
while _is_alive(thread):
15051520
thread.join(timeout=0.1)
15061521
finished.append(sum(thread.result))
15071522
callback(thread.i, request_count, end=True)
@@ -1514,9 +1529,10 @@ def consumer(q, request_count):
15141529
start = timeit.default_timer()
15151530
prod_thread.start()
15161531
cons_thread.start()
1517-
while prod_thread.isAlive():
1532+
_is_alive = thread_is_alive
1533+
while _is_alive(prod_thread):
15181534
prod_thread.join(timeout=0.1)
1519-
while cons_thread.isAlive():
1535+
while _is_alive(cons_thread):
15201536
cons_thread.join(timeout=0.1)
15211537

15221538
stop = timeit.default_timer()
@@ -1584,9 +1600,10 @@ def producer(q, requests, request_count):
15841600
finished = []
15851601

15861602
def consumer(q, request_count):
1603+
_is_alive = thread_is_alive
15871604
while len(finished) < request_count:
15881605
thread = q.get(True)
1589-
while thread.isAlive():
1606+
while _is_alive(thread):
15901607
thread.join(timeout=0.1)
15911608
finished.append(thread.result)
15921609
callback(thread.i, request_count, end=True)
@@ -1599,9 +1616,10 @@ def consumer(q, request_count):
15991616
start = timeit.default_timer()
16001617
prod_thread.start()
16011618
cons_thread.start()
1602-
while prod_thread.isAlive():
1619+
_is_alive = thread_is_alive
1620+
while _is_alive(prod_thread):
16031621
prod_thread.join(timeout=0.1)
1604-
while cons_thread.isAlive():
1622+
while _is_alive(cons_thread):
16051623
cons_thread.join(timeout=0.1)
16061624

16071625
stop = timeit.default_timer()

0 commit comments

Comments
 (0)