我使用 RPyC 连接到客户端并使用参数对象调用服务公开方法。我想从暴露的方法中获取这个对象并用它做一些事情,但是这个对象是弱引用的,当时我想访问它的数据:我得到一个 ReferenceError 告诉我对象“弱引用对象没有不再存在”
如何从垃圾收集中保护具有弱引用的对象?如何将其更改为强引用?
server.py(发送消息)
conn = rpyc.connect(ip,port)
bgsrv = rpyc.BgServingThread(conn)
conn.root.my_remote_method(a, b, c) # a,b,c are integer, strings etc.
time.sleep(0.2)
bgsrv.stop()
conn.close()
client.py(处理数据并将其放入队列)
class MessageService(Service):
def exposed_my_remote_method(self, a, b, c):
ThreadedClient.queue.put([a,b,c])
other.py(读取队列)
def read_queue(self):
""" Handle all the messages currently in the queue (if any) """
while ThreadedClient.queue.qsize():
try:
msg = ThreadedClient.queue.get(0)
self.read_message(msg)
except Queue.Empty:
pass
def read_message(self, msg):
# do something with the data of a, b, c
res = msg[0] + xy # ReferenceError