0

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?

S_J
  • 1
  • 2

1 Answers1

0

You're right, by design, Pyro only allows you to call remote methods that you explicitly exposed. This means that methods from the super class are NOT exposed.

There are several ways to access them remotely anyway (see https://pyro4.readthedocs.io/en/stable/servercode.html#exposing-classes-and-methods-without-changing-existing-source-code) but that's not the solution in this case. You probably don't want to control the way your server is dealing with concurrency (threads, in this case) remotely.

Why don't you make use of the fact that the default server type that Pyro4 uses, is already a multithreaded server? And you can control certain aspects of the way Pyro takes care of your objects (for instance, to have it create a new instance for every call if you want this) https://pyro4.readthedocs.io/en/stable/servercode.html#controlling-instance-modes-and-instance-creation

Finally, Pyro4 comes with a few examples that already implement a chat box and a messaging system so you may want to take a look at those (chatbox and messagebus at least), perhaps they can show you an alternate solution to what you want to do.

Irmen de Jong
  • 2,739
  • 1
  • 14
  • 26