I have to build a simple distributed ring-structured p2p system in which a producer and consumer interact with each other for transacting. We are required to build it using threads or sockets. I have been using Pyro but I cannot figure out how to handle producer or consumer threads. Ideally, a consumer would spawn a thread to send a request to its both neighbors. Neighbors could be consumers or producers and forward the request to their neighbors. If a producer is found, the request is SUPPOSED to trace back to the origin(consumer) before a direct connection is established between prod and cons and the transaction takes place.
It is required to spawn threads for either each new message or manage a thread pool. What I have so far is a Pyro class that looks like:
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)
I tried to make the Peer class a subclass of threading.Thread class but when I used Pyro proxies to call the start() method of threads it gave me an error:
AttributeError: remote object 'PYRO:obj_32f7c4e3f79146ac94a3389303e45361@localhost:35275' has no exposed attribute or method 'start'
Can remote objects not access superclass methods? How do I go about fixing this?