2017-07-30 94 views
1

在多線程應用程序中,我從線程調用rpyc.Connection.serve_all()時,其他線程無法立即使用該連接。RPyC serve_all阻止線程訪問連接

我認爲serve_all阻塞連接,其他線程只有在有一些超時時才能訪問它。

此代碼應重現問題

服務器:

#!/usr/bin/env python3 

import rpyc 
import rpyc.utils.server 
import threading 

class Service(rpyc.Service): 
    def on_connect(self): 
     print("New connection") 

    def on_disconnect(self): 
     print("Connection closed") 

    def exposed_get_status(self): 
     return "Test string" 

server = rpyc.utils.server.ThreadedServer(Service, port = 12345) 
t = threading.Thread(target = server.start) 
t.daemon = True 
t.start() 
t.join() 

客戶:

#!/usr/bin/env python3 

import rpyc 
import threading 
import datetime 

con = rpyc.connect('localhost',12345) 

def delayed(): 
    print("Time is up") 
    now = datetime.datetime.now() 
    print(con.root.get_status()) 
    print(str(datetime.datetime.now() - now)) 

timer = threading.Timer(10,delayed) 

print("Starting timer") 
timer.start() 
print("serving all") 
con.serve_all() 

樣本輸出(從客戶端):

$ python3 testrpyc.py 
Starting timer 
serving all 
Time is up 
Test string 
0:01:30.064087 

我使用RPyC 3。 4.3在Python 3.5.4rc1(debian sid)上安裝了pip。

我想我濫用serve_all,但我在文檔中找不到任何東西。

回答

0

(我回答)

我打開GitHub上一個issue,似乎這是正常的。解決方案是僅對任何資源的單個線程使用執行IO。