【发布时间】:2019-07-24 12:03:12
【问题描述】:
我必须构建一个简单的分布式环结构 p2p 系统,其中生产者和消费者相互交互以进行交易。我们需要使用线程或套接字来构建它。我一直在使用 Pyro,但我不知道如何处理生产者或消费者线程。理想情况下,消费者会产生一个线程来向其两个邻居发送请求。邻居可以是消费者或生产者,并将请求转发给他们的邻居。如果找到生产者,则在 prod 和 cons 之间建立直接连接并进行交易之前,该请求应该追溯到源(消费者)。
需要为每条新消息生成线程或管理线程池。到目前为止,我有一个 Pyro 类,它看起来像:
import threading
import Pyro4
class Peer(object):
def __init__():
#sets up quantity, lock, id, neighbourlist
#neighbour list has max 2 entries
def lookup():
# creates a msg object to be sent to forward()
def forward():
#sends msg to neighbors by creating proxies and calling
#the receive method on them
def receive():
#called when a msg is received. acquires lock and accesses the
#quantity. releases lock if not a producer or quantity is low
class Message(object):
def __init__(params):
#sets up a message object with the given params like
#msgid, consumerid, quan, producerid, forwarder_id(so that the message is not sent backwards)
我试图让 Peer 类成为 threading.Thread 类的子类,但是当我使用 Pyro 代理调用线程的 start() 方法时,它给了我一个错误:
AttributeError: 远程对象 'PYRO:obj_32f7c4e3f79146ac94a3389303e45361@localhost:35275' 没有暴露的属性或方法 'start'
远程对象不能访问超类方法吗?我该如何解决这个问题?
【问题讨论】:
-
请修正您问题的格式/布局,并使用有效的 Python 语法
-
对此感到抱歉。更新
标签: python multithreading rmi distributed-system pyro