Python learning notes (threading multithreading), pythonthreading
The blogger optimized the interface framework yesterday and wanted to add more functions.
Think of performance stress tests on interfaces
Tools used before work, such as loadrunner and jmeter
I want to test the interface performance with python.
First, we need to apply this function to the threading module of python.
The following code is learned by yourself:
1 #! /Usr/bin/env python 2 #-*-coding: utf_8-*-3 4 import threading 5 import requests 6 from time import ctime 7 8 9 def api (url, data): 10 try: 11 r = requests. post (url, data) 12 print "interface access return Status Code:", r. status_code13 print "API request time:", ctime () 14 print "API access return address:", r. url15 failed t Exception. _ bases __: 16 print "interface Access failed", "Interface request time:", ctime () 17 18 case_1 = {'username': 'admin', 'Password ': '000000'} 20 url1 = 'HTTP: // localhost: 123456/swcw/back/sysLogin. action '21 22 23 threads = [] 24 for I in range (10): 25 t_ I = threading. thread (target = api (url1, case_1) 26 threads. append (t_ I) 27 28 if _ name _ = '_ main _': 29 for t in threads: 30 t. setDaemon (True) 31 t. start () 32 t. join () 33 34 print "all over % s" % ctime ()
This is a scenario where 10 processes log on simultaneously.
Then add some performance running result data in the form of a class.
Finally, I recommend a blog about multithreading that is easy to understand.
The bloggers also learned from the above.
Http://www.cnblogs.com/fnng/p/3670789.html