【问题标题】:RPyC serve_all blocking threads access to connectionRPyC serve_all 阻塞线程访问连接
【发布时间】:2017-07-30 20:05:19
【问题描述】:

在多线程应用程序中,我从一个线程调用rpyc.Connection.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

我在安装了 pip 的 Python 3.5.4rc1 (debian sid) 上使用 RPyC 3.4.3。

我认为我在滥用serve_all,但我在文档中找不到任何内容。

【问题讨论】:

    标签: python multithreading rpyc


    【解决方案1】:

    (回答自己)

    我在github上开了一个issue,看来这很正常。解决方案是对任何资源仅在单个线程上执行 IO。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      • 2023-04-09
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      相关资源
      最近更新 更多