首页 > 编程语言 > 详细

Python多线程

时间:2020-01-09 17:37:25      阅读:61      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/python3

import pymysql
import os
import datetime
import threading
import time

import requests

rangetime = 100

start = datetime.datetime.now()
os.environ[NLS_LANG] = SIMPLIFIED CHINESE_CHINA.UTF8



class myThread (threading.Thread):
    def __init__(self, threadID, name, counter):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.counter = counter
    def run(self):
        print ("开始线程:" + self.name)
        print_time(self.name, self.counter)
        print ("退出线程:" + self.name)

def print_time(threadName, counter):
    while counter:
        # 执行业务
        url = "https://chp.shadiao.app/api.php"
        time.sleep(1)
        r = download_page(url)
        list = []
        data = [r]
        list.append(data)
        result = bathInsertChpData(list)
        print(threadName,     **   , rangetime - counter ,   **   ,result)
        counter -= 1


def main():
    t_list=[]
    for i in range(80):     #启动线程数
        t = myThread(i, "Thread-%s"%i, rangetime)
        t_list.append(t)
        t.start()
    for t in t_list:
        t.join()
    print("退出主线程")


if __name__ == __main__:
    main()

 

Python多线程

原文:https://www.cnblogs.com/luxd/p/12172247.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!