Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sivel/speedtest-cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2019-01-23 20:33:30 +0300
committerMatt Martz <matt@sivel.net>2019-01-23 20:33:30 +0300
commitca2250f700e1e9c70d3c97fa5d091c69bbae7a9f (patch)
treebb75c3b2dec72a55abc010e7ebc7ff6f4c07b6b8
parentddb8db0c9458a8ce7ee3c9e82758fd1f943099b1 (diff)
Add functionality for single threaded testing. Fixes #571
-rwxr-xr-xspeedtest.py35
1 files changed, 27 insertions, 8 deletions
diff --git a/speedtest.py b/speedtest.py
index d44ff5d..a18435a 100755
--- a/speedtest.py
+++ b/speedtest.py
@@ -1436,8 +1436,12 @@ class Speedtest(object):
printer('Best Server:\n%r' % best, debug=True)
return best
- def download(self, callback=do_nothing):
- """Test download speed against speedtest.net"""
+ def download(self, callback=do_nothing, threads=None):
+ """Test download speed against speedtest.net
+
+ A ``threads`` value of ``None`` will fall back to those dictated
+ by the speedtest.net configuration
+ """
urls = []
for size in self.config['sizes']['download']:
@@ -1476,7 +1480,7 @@ class Speedtest(object):
finished.append(sum(thread.result))
callback(thread.i, request_count, end=True)
- q = Queue(self.config['threads']['download'])
+ q = Queue(threads or self.config['threads']['download'])
prod_thread = threading.Thread(target=producer,
args=(q, requests, request_count))
cons_thread = threading.Thread(target=consumer,
@@ -1498,8 +1502,12 @@ class Speedtest(object):
self.config['threads']['upload'] = 8
return self.results.download
- def upload(self, callback=do_nothing, pre_allocate=True):
- """Test upload speed against speedtest.net"""
+ def upload(self, callback=do_nothing, pre_allocate=True, threads=None):
+ """Test upload speed against speedtest.net
+
+ A ``threads`` value of ``None`` will fall back to those dictated
+ by the speedtest.net configuration
+ """
sizes = []
@@ -1557,7 +1565,7 @@ class Speedtest(object):
finished.append(thread.result)
callback(thread.i, request_count, end=True)
- q = Queue(self.config['threads']['upload'])
+ q = Queue(threads or self.config['threads']['upload'])
prod_thread = threading.Thread(target=producer,
args=(q, requests, request_count))
cons_thread = threading.Thread(target=consumer,
@@ -1625,6 +1633,10 @@ def parse_args():
parser.add_argument('--no-upload', dest='upload', default=True,
action='store_const', const=False,
help='Do not perform upload test')
+ parser.add_argument('--single', default=False, action='store_true',
+ help='Only use a single connection instead of '
+ 'multiple. This simulates a typical file '
+ 'transfer.')
parser.add_argument('--bytes', dest='units', action='store_const',
const=('byte', 8), default=('bit', 1),
help='Display values in bytes instead of bits. Does '
@@ -1839,7 +1851,10 @@ def shell():
if args.download:
printer('Testing download speed', quiet,
end=('', '\n')[bool(debug)])
- speedtest.download(callback=callback)
+ speedtest.download(
+ callback=callback,
+ threads=(None, 1)[args.single]
+ )
printer('Download: %0.2f M%s/s' %
((results.download / 1000.0 / 1000.0) / args.units[1],
args.units[0]),
@@ -1850,7 +1865,11 @@ def shell():
if args.upload:
printer('Testing upload speed', quiet,
end=('', '\n')[bool(debug)])
- speedtest.upload(callback=callback, pre_allocate=args.pre_allocate)
+ speedtest.upload(
+ callback=callback,
+ pre_allocate=args.pre_allocate,
+ threads=(None, 1)[args.single]
+ )
printer('Upload: %0.2f M%s/s' %
((results.upload / 1000.0 / 1000.0) / args.units[1],
args.units[0]),