本文整理汇总了Python中threadpool.ThreadPool.createWorkers方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.createWorkers方法的具体用法?Python ThreadPool.createWorkers怎么用?Python ThreadPool.createWorkers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threadpool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.createWorkers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gits_download
# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import createWorkers [as 别名]
def gits_download(self, url, output="/tmp", threads=20):
if not self.output:
self.output = output
results = self.index(url, output=output)
if not results:
return
args = [((i[0], i[1]), {}) for i in self.giturls]
# ... and build a WorkRequest object for each item in data
requests = makeRequests(self.callback,
args,
self.print_result,
self.handle_exception)
main = ThreadPool(threads)
for req in requests:
main.putRequest(req)
print "Work request #%s added." % req.requestID
i = 0
while True:
try:
main.poll()
print "Main thread working...",
print "(active worker threads: %i)" % (
threading.activeCount()-1, )
if i == 10:
print "**** Adding 3 more worker threads..."
main.createWorkers(3)
if i == 20:
print "**** Dismissing 2 worker threads..."
main.dismissWorkers(2)
i += 1
except KeyboardInterrupt:
print "**** Interrupted!"
break
except NoResultsPending:
print "**** No pending results."
break
if main.dismissedWorkers:
print "Joining all dismissed worker threads..."
main.joinAllDismissedWorkers()
示例2: int
# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import createWorkers [as 别名]
client.close()
studentID = '677cfc77e52778a3d5741cb5d5f358c537c28f5134d63e4b7f8376f73315922c'
host = ''
port = int(sys.argv[1])
backlog = 5
size = 1024
threads = 5
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(backlog)
sock = [s]
main = ThreadPool(threads)
main.createWorkers(threads)
while True:
if exit == 1:
main.joinAllDismissedWorkers()
sys.exit()
else:
requests = makeRequests(use_client, sock)
for req in requests:
main.putRequest(req)
updates = makeRequests(update_client, sock)
for update in updates:
main.putRequest(update)
time.sleep(0.5)
示例3:
# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import createWorkers [as 别名]
# [main.putRequest(req) for req in requests]
# ...and wait for the results to arrive in the result queue
# by using ThreadPool.wait(). This would block until results for
# all work requests have arrived:
# main.wait()
# instead we can poll for results while doing something else:
i = 0
while True:
try:
time.sleep(0.5)
main.poll()
print "Main thread working...",
print "(active worker threads: %i)" % (threading.activeCount()-1, )
if i == 10:
print "**** Adding 3 more worker threads..."
main.createWorkers(3)
if i == 20:
print "**** Dismissing 2 worker threads..."
main.dismissWorkers(2)
i += 1
except KeyboardInterrupt:
print "**** Interrupted!"
break
except NoResultsPending:
print "**** No pending results."
break
if main.dismissedWorkers:
print "Joining all dismissed worker threads..."
main.joinAllDismissedWorkers()