Python Learning Notes (threading Multithreading)

Source: Internet
Author: User

The blogger optimized the interface framework yesterday and wanted to add some more features.

Think of the performance stress test on the interface

Tools that were used before the work, such as: LoadRunner, JMeter

Thinking about this, we're going to use Python to implement performance stress testing on interfaces.

The first thing to do is to use Python's threading module to implement this function.

Here is the code that you learn to explore:

1 #!/usr/bin/env python2 #-*-coding:utf_8-*-3 4 ImportThreading5 ImportRequests6  fromTimeImportCTime7 8 9 defAPI (URL, data):Ten     Try: OneR =requests.post (URL, data) A         Print "Interface Access return status code:", R.status_code -         Print "interface Request time:", CTime () -         Print "Interface Access return address:", R.url the     exceptException.__bases__: -         Print "Interface Access failed","interface Request time:", CTime () -  -Case_1 = {'username':'Admin','Password':'123456'} -URL1 ='http://localhost:8081/swcw/back/sysLogin.action' +  A  atThreads = [] -  forIinchRange (10): -T_i = Threading. Thread (target=API (URL1, case_1)) - threads.append (t_i) -  - if __name__=='__main__': in      forTinchThreads: - T.setdaemon (True) to T.start () + T.join () -  the     Print "All over %s"% CTime ()

This is a 10-process simultaneous login scenario

After that, you add some performance data to the class form.

Finally I recommend a multi-threaded blog easy to understand

The blogger himself also learned from the above

Http://www.cnblogs.com/fnng/p/3670789.html

Python Learning Notes (threading Multithreading)

Related Article

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.