本文介绍了python和pypy之间的多处理侦听器和客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以有一个侦听器服务器进程和一个客户端进程,其中他们中的一个使用python解释器,另一个使用 pypy 解释器?

Is it possible to have a Listener server process and a Client process where one of them uses a python interpreter and the other a pypy interpreter?

conn.send()conn.recv()是否可以很好地互操作?

Would conn.send() and conn.recv() interoperate well?

推荐答案

我尝试查看:

import sys
from multiprocessing.connection import Listener, Client

address = ('localhost', 6000)

def client():
    conn = Client(address, authkey='secret password')
    print conn.recv_bytes()
    conn.close()

def server():
    listener = Listener(address, authkey='secret password')
    conn = listener.accept()
    print 'connection accepted from', listener.last_accepted
    conn.send_bytes('hello')
    conn.close()
    listener.close()

if __name__ == '__main__':
    if sys.argv[1] == 'client':
        client()
    else:
        server()

这是我得到的结果:

  • CPython 2.7 + CPython 2.7:工作
  • PyPy 1.7 + PyPy 1.7:工作
  • CPython 2.7 + PyPy 1.7:不起作用
  • CPython 2.7 + PyPy Nightly(pypy-c-jit-50911-94e9969b5f00-linux64):工作
  • CPython 2.7 + CPython 2.7: working
  • PyPy 1.7 + PyPy 1.7: working
  • CPython 2.7 + PyPy 1.7: not working
  • CPython 2.7 + PyPy Nightly (pypy-c-jit-50911-94e9969b5f00-linux64): working

在使用PyPy 1.7时(无论是哪个服务器和哪个客户端都没有关系),IOError: bad message length会报告错误.这也反映了关于pypy-dev邮件列表的报告.但是,此问题最近已修复(可在每晚版本中运行),因此,下一版本(大概为1.8)也应修复.

When using PyPy 1.7 (doesn't matter which is the server and which is the client), an error is reported with IOError: bad message length. This also mirrors the report on the pypy-dev mailing list. However, this was recently fixed (it works in nightly build), so the next version (presumably 1.8) should have it fixed as well.

之所以如此,是因为多处理模块使用Python的 pickle 模块,稳定,并在多个Python实现(甚至PyPy)中受支持.

In general, this works because the multiprocessing module uses Python's pickle module, which is stable and supported across multiple Python implementations, even PyPy.

这篇关于python和pypy之间的多处理侦听器和客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:17