码迷,mamicode.com
首页 > 编程语言 > 详细

Python线程池任务

时间:2019-02-23 14:46:18      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:return   class   exec   form   线程   print   exe   sub   task   

#!/usr/bin/env python
# -*- coding:utf-8 -*-
from concurrent.futures import ThreadPoolExecutor
#线程池,导入模块
import time

def task(hostname):
    ‘‘‘
    假设这里是要提交的任务
    :param hostname: 
    :return: 
    ‘‘‘
    time.sleep(2)
    print(hostname)

#创建线程池线程数自定义,要看主机性能,例如创建20个线程
pool = ThreadPoolExecutor(20)

for i in range(1,101):
    #100个任务
    hostname = c{}.com.format(i)
    pool.submit(task,hostname

 

Python线程池任务

标签:return   class   exec   form   线程   print   exe   sub   task   

原文地址:https://www.cnblogs.com/michael2018/p/10422600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!