Python进程间通信,使用multiprocessing.connection的Listener和Client实现
2017-11-21 11:46
781 查看
A进程代码
B进程代码
参考:http://outofmemory.cn/code-snippet/1715/python-usage-Connection-achieve-duojincheng-between-correspond
#encoding=utf-8 __author__ = 'outofmemory.cn' from multiprocessing.connection import Listener address = ('localhost', 6000) # family is deduced to be 'AF_INET' listener = Listener(address, authkey='secret password') while True: conn = listener.accept() print 'connection accepted from', listener.last_accepted data = conn.recv() print data try: result = 'haha' conn.send_bytes('get %s'%(result,)) except Exception,e: print e finally: conn.close() listener.close() |
B进程代码
#encoding=utf-8 __author__ = 'outofmemory.cn' from multiprocessing.connection import Client address = ('localhost', 6000) for x in range(0,10): conn = Client(address, authkey='secret password') conn.send('这是一个美丽的世界') print conn.recv_bytes() conn.close() |
参考:http://outofmemory.cn/code-snippet/1715/python-usage-Connection-achieve-duojincheng-between-correspond
相关文章推荐
- 如何使用Python实现进程间通信
- 使用Python的Queue实现线程/进程间通信
- Androidpn的使用[找不到org.androidpn.client.PersistentConnectionListener]
- android(21)(使用HttpURLConnection,HttpClient和AsyncHttpClient分别实现post和get请求数据)
- Python使用multiprocessing实现一个最简单的分布式作业调度系统
- 使用HttpClient的PoolingHttpClientConnectionManager实现Http请求连接池
- Androidpn的使用[找不到org.androidpn.client.PersistentConnectionListener
- Python使用multiprocessing实现一个最简单的分布式作业调度系统
- XMPP在android客户端上的应用 Androidpn的使用[找不到org.androidpn.client.PersistentConnectionListener]
- Androidpn的使用[找不到org.androidpn.client.PersistentConnectionListener]
- 在python中实现生产者和消费者的例子(一):使用multiprocessing和pipe()
- Androidpn的使用[找不到org.androidpn.client.PersistentConnectionListener]
- XMPP在android客户端上的应用 Androidpn的使用[找不到org.androidpn.client.PersistentConnectionListener]
- 使用Python的multiprocessing.connections实现远程方法调用(RPC)
- Python使用multiprocessing实现一个最简单的分布式作业调度系统
- 在python中实现生产者和消费者的例子(二):使用multiprocessing和queue
- 使用gconf-dbus实现进程间通信注意事项
- 使用微软消息队列实现C#进程间通信(一)
- 使用微软消息队列实现C#进程间通信(转)
- 使用clientlistener和serverlistener刷新InlineFrame