我有一個python應用程序創建一個子進程,打開一個套接字與它通信,然後通過套接字創建一個multiprocessing.connection對象。連接對象使用共享密鑰(隨機生成)和hmac來確保不允許其他進程通過連接進行通信。python multiprocessing.connection報告「AuthenticationError:摘要收到錯了」
在Linux上,此功能完美無缺。在Windows中,我得到的錯誤:
multiprocessing.AuthenticationError: digest received was wrong
最關鍵的是這是由它的標準輸入發送到子之前醃製隨機產生的比特串:
authkey = ''.join([chr(random.getrandbits(7)) for i in range(20)])
而且我仔細說檢查
print "key:", ' '.join([str(ord(x)) for x in authkey])
服務器開始:
在連接的兩端此-A-道路上的關鍵比賽210l = multiprocessing.connection.Listener(
('localhost', int(port)), authkey=authkey)
..和客戶端開始:
c = multiprocessing.connection.Client(
('localhost', int(port)), authkey=authkey)
兩個進程都在同一臺機器上運行,用相同的Python版本。我發現如果我修復了關鍵字(比如authkey ='test'),那麼我第一次運行該程序時仍然會得到AuthenticationError,但是在後續運行時卻不會。
嗨@Luke,你是怎麼用'os.urandom'生成密鑰的?我的服務器進程和客戶端進程分佈在兩臺不同的linux機器上。儘管他們使用相同的字符串鍵,但我得到了這個錯誤。 – Jon
這只是'authkey = os.urandom(20)'。請參閱:https://github.com/pyqtgraph/pyqtgraph/blob/develop/pyqtgraph/multiprocess/processes.py#L73 – Luke