本文整理汇总了Python中threadpool.ThreadPool.joinAllDismissedWorkers方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.joinAllDismissedWorkers方法的具体用法?Python ThreadPool.joinAllDismissedWorkers怎么用?Python ThreadPool.joinAllDismissedWorkers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threadpool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.joinAllDismissedWorkers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gits_download
# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import joinAllDismissedWorkers [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: ThreadPool
# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import joinAllDismissedWorkers [as 别名]
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)
main.poll()
s.close
if main.dismissedWorkers:
print("Joining all dismissed worker threads...")
main.joinAllDismissedWorkers()