本文整理汇总了Python中threading.Thread.run_number方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.run_number方法的具体用法?Python Thread.run_number怎么用?Python Thread.run_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threading.Thread
的用法示例。
在下文中一共展示了Thread.run_number方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run_number [as 别名]
def download(self):
total_downloaded = 0
connections = [
self.connect(self.host) for i in range(self.runs)
]
total_start_time = time()
for current_file in SpeedTest.DOWNLOAD_FILES:
threads = []
for run in range(self.runs):
thread = Thread(
target=self.downloadthread,
args=(connections[run],
'%s?x=%d' % (current_file, int(time() * 1000))))
thread.run_number = run + 1
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
total_downloaded += thread.downloaded
LOG.debug('Run %d for %s finished',
thread.run_number, current_file)
total_ms = (time() - total_start_time) * 1000
for connection in connections:
connection.close()
LOG.info('Took %d ms to download %d bytes',
total_ms, total_downloaded)
return total_downloaded * 8000 / total_ms
示例2: upload
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run_number [as 别名]
def upload(self):
connections = [
self.connect(self.host) for i in range(self.runs)
]
post_data = [
urlencode({'content0': content(s)}) for s in SpeedTest.UPLOAD_FILES
]
total_uploaded = 0
total_start_time = time()
for data in post_data:
threads = []
for run in range(self.runs):
thread = Thread(target=self.uploadthread,
args=(connections[run], data))
thread.run_number = run + 1
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
LOG.debug('Run %d for %d bytes finished',
thread.run_number, thread.uploaded)
total_uploaded += thread.uploaded
total_ms = (time() - total_start_time) * 1000
for connection in connections:
connection.close()
LOG.info('Took %d ms to upload %d bytes',
total_ms, total_uploaded)
return total_uploaded * 8000 / total_ms
示例3: download
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run_number [as 别名]
def download(self, urls=None):
total_downloaded = 0
if urls is None:
connections = [self.connect(self.host) for i in range(self.runs)]
else:
connections = [self.connect(h['host']) for h in urls]
total_start_time = time()
for current_file in self.DOWNLOAD_FILES:
threads = []
for run in range(self.runs):
thread = Thread(
target=self.downloadthread,
args=(connections[run],
'%s?x=%d' % (current_file, int(time() * 1000))
if urls is None else urls[run]['url']))
thread.run_number = run + 1
thread.start()
threads.append(thread)
for thread in threads:
try:
thread.join()
total_downloaded += thread.downloaded
util.debug('[SC] Run %d for %s finished' %
(thread.run_number, current_file))
except:
pass
total_ms = (time() - total_start_time) * 1000
for connection in connections:
connection.close()
util.info('[SC] Took %d ms to download %d bytes' % (total_ms,
total_downloaded))
return total_downloaded * 8000 / total_ms
示例4: download
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run_number [as 别名]
def download(exclude=[]):
total_downloaded = 0
connections = []
for run in range(RUNS):
connection = httplib.HTTPConnection(HOST)
connection.set_debuglevel(HTTPDEBUG)
connection.connect()
connections.append(connection)
total_start_time = time()
for current_file in [x for x in DOWNLOAD_FILES if x not in exclude]:
threads = []
for run in range(RUNS):
thread = Thread(target=downloadthread,
args=(connections[run], current_file))
thread.run_number = run
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
total_downloaded += thread.downloaded
printv('Run %d for %s finished' %
(thread.run_number, current_file))
total_ms = (time() - total_start_time) * 1000
for connection in connections:
connection.close()
printv('Took %d ms to download %d bytes' % (total_ms, total_downloaded))
return (total_downloaded * 8000 / total_ms)
示例5: upload
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run_number [as 别名]
def upload():
connections = []
for run in range(RUNS):
connection = httplib.HTTPConnection(HOST)
connection.set_debuglevel(HTTPDEBUG)
connection.connect()
connections.append(connection)
post_data = []
ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
for current_file_size in UPLOAD_FILES:
values = {'content': ''.join(random.choice(ALPHABET)
for i in range(current_file_size))}
post_data.append(urllib.urlencode(values))
total_uploaded = 0
total_start_time = time()
for data in post_data:
threads = []
for run in range(RUNS):
thread = Thread(target=uploadthread, args=(connections[run], data))
thread.run_number = run
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
printv('Run %d for %d bytes finished' %
(thread.run_number, thread.uploaded))
total_uploaded += thread.uploaded
total_ms = (time() - total_start_time) * 1000
for connection in connections:
connection.close()
printv('Took %d ms to upload %d bytes' % (total_ms, total_uploaded))
return (total_uploaded * 8000 / total_ms)
示例6: upload
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run_number [as 别名]
def upload(self):
""" Perform multiple uploads in threads."""
connections = []
for run in range(self.runs):
connections.append(self.connect(self.host))
post_data = []
for current_file_size in SpeedTest.UPLOAD_FILES:
values = {
'content0': ''.join(
random.choice(SpeedTest.ALPHABET) for i in range(current_file_size))
}
post_data.append(urlencode(values))
total_uploaded = 0
total_start_time = time()
for data in post_data:
threads = []
for run in range(self.runs):
thread = Thread(target=self.uploadthread,
args=(connections[run], data))
thread.run_number = run + 1
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
logging.info('Run %d for %d bytes finished',
thread.run_number, thread.uploaded)
total_uploaded += thread.uploaded
total_ms = (time() - total_start_time) * 1000
for connection in connections:
connection.close()
logging.info('Took %d ms to upload %d bytes',
total_ms, total_uploaded)
return total_uploaded * 8000 / total_ms