Python multi-process communication module

Source: Internet
Author: User
Multi-process communication methods are many, different and several. Just tried python encapsulated the multi-process communication module multiprocessing.connection.

Simple test, efficiency can also, should be tied to the socket package, the efficiency can reach 4krps, can meet the needs of many aspects.

The accompanying code is as follows:

Client

#!/usr/bin/python#-*-coding:utf-8-*-"" "Download-slave" "__author__ = ' zagfai ' __license__ = ' MIT@2014-02 '  impor T webtulfrom multiprocessing.connection Import Client  a = 0try: While    True:        A + = 1        address = (' 10.33.41.1 6666)        conn = Client (address, authkey= ' Hellokey ')        #print conn.recv ()        d = conn.recv ()        conn.close () Except:    Passprint A

Server

#!/usr/bin/python#-*-coding:utf-8-*-"" "Downloader-master Server" "" __author__ = ' zagfai ' __license__ = ' MIT@2014-02 ' C0/>import webtulfrom multiprocessing.connection Import listenerfrom Threading Import Thread  def Listener ():    Address = (' 10.33.41.112 ', 6666)    listener = Listener (address, backlog=100, authkey= ' Hellokey ') while    True:        conn = listener.accept ()        #print ' connection accepted from ', listener.last_accepted        try:            conn.send ({ ' 1 ': 2, ' 2 ': ' abc '})        except Exception, E:            print e        finally:            conn.close ()    listener.close ()  listener_th = Thread (target=listener) Listener_th.daemon = Truelistener_th.start () listener_th.join (timeout=20 )
  • 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.