-1

I'm new to Pyro and pretty new to Python.

I have the following setup: 2 python scripts

Here is server.py:

import os
import sys

import Pyro4

class Packet(object):

    must_shutdown = False

    def __init__(self):
        self.some_attr = ""

    def close_connection(self):
        self.must_shutdown=True

def main():
    try:
        daemon = Pyro4.Daemon(host="localhost", port=65432)
        packet = Packet()
        uri = daemon.register(packet, "my.packet")

        print "Ready. Object uri =", uri

        daemon.requestLoop(loopCondition=lambda: not packet.must_shutdown)
        print "after loop"

    except Exception, e:
        print "Exception" + str(e)
    finally:
        print "Finally"

if __name__ == '__main__':
    main()

and this is client.py:

import os
import sys

import Pyro4

def main():
    try:

        packet = Pyro4.Proxy("PYRO:my.packet@localhost:65432")

        packet.some_attr = "this is client"

        packet.close_connection()

        print "client exiting"

    except Exception, e:
        print "Exception: " + str(e)
    finally:
        print "Finnally"

if __name__ == '__main__':
    main()

As you noticed, in server.py, in the requestloop there is a loopCondition "listening" for packet.must_shutdown to change to True. I start server.py and then client.py. The Pyro Packet object in client.py is obtained successfully. The problem is that even though I call close_connection method on the Pyro Packet object, thus setting must_shutdown to "True", the requestLoop does not break and the server still listening for requests. I log in close_connection and it is called but the interesting thing is that self.some_attr is still empty even thought it was set in client.py. It is like, somehow, client deals with another instance of Packet object than the one instantiated in server. What I'm missing here?

Ispas Claudiu
  • 1,890
  • 2
  • 28
  • 54
  • The server.py code won't run as printed above. It has an error where you're creating the packet object. Also, the server object doesn't expose anything, which Pyro4 will print a warning about. Can you please replace the code above with the actual code you're running? – Irmen de Jong Sep 06 '19 at 22:32
  • Indeed I was sending the daemon object as parameter for the Packet. It is no longer the case, edited. As for the '@expose', I use an older version pf Pyro4 which does not function with annotations like '@expose'. – Ispas Claudiu Sep 09 '19 at 07:00
  • a Pyro version that doesn't have @expose is ancient and no longer supported. If there are any 'bugs' in this old version they're most likely already fixed in the current release. – Irmen de Jong Sep 09 '19 at 16:12
  • Also, you should at least mention the Pyro4 version you're using. – Irmen de Jong Sep 09 '19 at 22:58

2 Answers2

0

I found my issue in this thread which may be considered as duplicate: requestloop(loopCondition) doesn't release even after loopCondition is False. The problem was that I didn't set Pyro4.config.COMMTIMEOUT which by default is set to 0 and for some reason it doesn't care to check if requestLoop condition is satisfied or not. This is not specified in the requestLoop docs!

However I met a strange behavior which I consider a bug inside Pyro4.

Ispas Claudiu
  • 1,890
  • 2
  • 28
  • 54
  • Current version of Pyro4 have no problem with this. They frequently check the requestloop condition, whether you use a communication timeout or not. Please upgrade your Pyro4 version before investigating or reporting bugs or problems that have been fixed a long time ago. – Irmen de Jong Sep 09 '19 at 22:57
  • Why do you think that updating is the easy way? Because it's a general solution? Not everyone works on personal projects that can be updated instantly, some of us work on more complex projects on which updating even a third party software cannot be done as you expect. So I feel free to report any bugs/problems on any version as long as I need a fix/workaround on that particular version. – Ispas Claudiu Sep 10 '19 at 09:15
-1

Fixing the issues I mentioned int he comment will probably provide you with the answer.

Most notably; https://pyro4.readthedocs.io/en/stable/clientcode.html#accessing-remote-attributes where it says "you can access exposed attributes of your remote objects directly via the proxy." (emphasis added)

Irmen de Jong
  • 2,739
  • 1
  • 14
  • 26
  • The issues was just a miss translation from my original code. It should've get me Python errors and not logical communication. However, thanks for the implication. – Ispas Claudiu Sep 09 '19 at 07:09