Python learning notes (threading multithreading), pythonthreading

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.