2011-12-28 46 views

回答

10

我嘗試過了,看看:

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每晚(pypy-C-JIT-50911-94e9969b5f00-LINUX64):工作

當使用PyPy 1.7(無關緊要其是在服務器和其客戶端),錯誤報告爲IOError: bad message length。這也反映了the report on the pypy-dev mailing list。然而,最近這個問題已經得到解決(它在每晚構建中起作用),所以下一個版本(推測是1.8)也應該修復它。

一般來說,這是可行的,因爲多處理模塊使用Python的pickle模塊,該模塊在多個Python實現中都很穩定並且受支持,甚至是PyPy。

+0

這真棒,你發現錯誤報告! – Jonathan 2011-12-28 19:09:43

+0

謝謝你測試這個! – Demolishun 2012-01-14 20:53:57

相關問題