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
Copy the Code code as follows:
#!/usr/bin/python
#-*-Coding:utf-8-*-
"" "Download-slave
"""
__author__ = ' Zagfai '
__license__ = ' mit@2014-02 '
Import Webtul
From multiprocessing.connection import Client
A = 0
Try
While True:
A + = 1
Address = (' 10.33.41.112 ', 6666)
conn = Client (address, authkey= ' Hellokey ')
#print Conn.recv ()
D = CONN.RECV ()
Conn.close ()
Except
Pass
Print a
Server
Copy the Code code as follows:
#!/usr/bin/python
#-*-Coding:utf-8-*-
"" "Downloader-master server
"""
__author__ = ' Zagfai '
__license__ = ' mit@2014-02 '
Import Webtul
From multiprocessing.connection import Listener
From 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 = True
Listener_th.start ()
Listener_th.join (TIMEOUT=20)