python中用多线程+并发跑百万次任务贼快
Python中使用线程有两种方式:函数或者用类来包装线程对象。
函数式:调用 _thread 模块中的start_new_thread()函数来产生新线程。语法如下:
_thread.start_new_thread ( function, args[, kwargs] )
参数说明:
function - 线程函数。
args - 传递给线程函数的参数,他必须是个tuple类型。
kwargs - 可选参数。
# -*- coding:utf-8 -*-
"""
@ Author: Coolang
@ Url: http://www.coolang.cn
@ Connect: coolang@outlook.com
@ Datetime: 2020/6/27:7:08
@ FileName: c_test_threading.py
@ IDE: PyCharm
@ Plan:练习多线程
"""
import _thread
import time
# 定义一个线程函数
def print_time(threadName, delay):
count = 0
while count < 10:
#time.sleep(delay)
count += 1
ftime = float(</