# -*- coding: UTF-8 -*- # Author : LinYaoHong # Date : 2019/8/20 23:01 # Filename: test.py # Tools : PyCharm import time, pymysql, gevent def func(m, n): conn = pymysql.connect(host='localhost', port=3306, user="root", password='111111', db="test") cursor = conn.cursor() for i in range(m, n): name = "lin" + str(i) gender = "男" email = "lin" + str(i) + "@qq.com" if i % 2 == 0: gender = "女" sql = "insert into user(name,gender,email) values(%s,%s,%s)" cursor.execute(sql, (name, gender, email)) conn.commit() # gevent.sleep(3) cursor.close() conn.close() start_time = time.time() gevent.joinall([ # gevent.spawn(func, 1, 6000), gevent.spawn(func, 1, 1000000), gevent.spawn(func, 1000000, 2000000), gevent.spawn(func, 2000000, 3000000), gevent.spawn(func, 3000000, 4000000), gevent.spawn(func, 4000000, 5000000), ]) stop_time = time.time() print('run time is %s' % (stop_time-start_time))