irmen / Pyro4

Pyro 4.x - Python remote objects
http://pyro4.readthedocs.io/
MIT License
715 stars 83 forks source link

Daemon active connections not updated #207

Closed nedo99 closed 5 years ago

nedo99 commented 5 years ago

Hi,

I would like to get information about connected client/proxy objects to a daemon. The scenario that I would like to have is daemon information about when it received last remote call to an exposed objects. Right now I cannot find that information. I tried using objectsById https://pythonhosted.org/Pyro4/api/core.html#Pyro4.core.Daemon.objectsById which has information about connected object proxies, but after client/proxy object process gets killed, the object is still in the list so I do not have information if I can terminate the daemon.

Is there another way to get this data?

Kind regards, Nedim

irmen commented 5 years ago

(update your bookmarks, you're linking to the obsolete documentation. Please use https://pyro4.readthedocs.io/ instead)

objectsById has nothing to do with the connections that are currently active in the daemon. It's the set of pyro server objects registered to said daemon.

Can you rewrite your problem in terms of a "resource" that gets allocated when a client connects, and has to be "freed"/"deallocated" when the client disconnects? You can use Pyro4's resource tracking feature then. See the resourcetracking example .

Or maybe the daemon's validateHandshake and clientDisconnect methods suit your problem better.

Under the hood, the connections that are active are not stored in the daemon itself. The way connections are kept track of depends on the type of pyro server you're running (multiplexed or threadpool). It's not advisable to poke around in their insides to somehow get this server-specific information into your own code.

nedo99 commented 5 years ago

Hello,

clientDisconnect was good approach, since method is called whenever client gets disconnected, but with one corner case. clientDisconnect is also called if client uses aync call, which means that in that case we do not know if client really closed the connection or it is just really long call.

It would be good if we could differentiate these two.

Regards, Nedim

irmen commented 5 years ago

That's not possible right now. I guess you should be looking into managing your own remote resources explicitly rather than depending on the exact moment Pyro creates and releases a connection.

The reason this happens with async calls btw is that it needs a new connection to run the call out of band with the existing proxy connection. If it was going to reuse the existing connection, all async calls wouls stil be performed in a purely sequential manner and we have gained nothing.