[Python] multi-thread asynchronous execution of multiple functions at the same time

Source: Internet
Author: User

CodeAs follows:

I have not fully thought about it yet. Put it here and continue to develop ideas at the company.

# Coding: utf-8import sysimport osimport queueimport threadingfrom workerpool import workerpool, simplejobclass Manager (object): def _ init _ (Self): Self. threadpool = workerpool (5) def stop (Self): Self. threadpool. shutdown () def runsequencecmds (self, ip_addresses, func_list, use_root = false, queue = none): If queue is none: queue = queue. queue () for IP in ip_addresses: Self. threadpool. put (simplejob (queue, self. _ runsequencecmd, (IP, func_list, use_root),), Def _ runsequencecmd (self, IP, CMD, func_list, use_root = false): For func in func_list: go_on, result = func (CMD) if not go_on: breakdef main (): pass if _ name _ = '_ main _': Main ()

 

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.