ACS-Community / ACS

Official ACS community fork
MIT License
28 stars 26 forks source link

Non blocking Python Clients #43

Open marco-buttu opened 8 years ago

marco-buttu commented 8 years ago

If the manager is offline, then a Python client istantiation is blocking:

>>> from Acspy.Clients.SimpleClient import PySimpleClient
>>> client = PySimpleClient()
Acspy.Util.ACSCorba._Client.__init__ - manager is not available.
      This method will block until manager comes online!

But I would like to do something in this case (for instance, I would like the user to be aware of this), so currently, before to get the client, I am verifying the manager is online . Something like this:

>>> from Acspy.Util.ACSCorba import getManager
>>> if getManager():
...     client = PySimpleClient()

But these instructions are not atomc, so this approach is not reliable. What do you think about having a non blocking PySimpleClient()?

javarias commented 8 years ago

The idea of having non-blocking python client has been discussed in ALMA for a couple of years. However, it never was implemented, I do not know the reasons. Nonetheless, this would be a very nice thing to have in ACS.

If no one is opposed, then this ticket should be implemented. Let's wait a little bit for comments.

@marco-buttu would you volunteer to implement this?

tjuerges commented 8 years ago

If I remember correctly I have implemented a non-blocking client in C++ a long time ago (>10 years?). Perhaps this could serve as a blue print?

marco-buttu commented 8 years ago

@javarias: ok

javarias commented 8 years ago

@tjuerges I think it is a good idea to have your implementation of a non-blocking client as a blue-print. Could you release the client code under a free software license and attach the source code file to this ticket?

tjuerges commented 8 years ago

@javarias OK. I scavenged my own Subversion repos and did the same to all the source codes on my several computers. Unfortunately I cannot find the example code and it seems that I do not have a copy any more. But I am quite certain that I have sent example code to either the (very) old mailing list or to Gianluca or submitted it to the old examples repo at ESO.

Anyway, the recipe is quite simple: instanciate a simple client and call the run method in a new thread with a timeout of let's say 5s in a loop (in that thread). That loop then checks during every iteration if a stop flag was set by some external entity and leaves the endless cycle if that flag got set.

tjuerges commented 8 years ago

Good news! Eventually I found the source code.

Argh! Github does not allow me to attach a tarball. Do we have an upload area?

moraklein commented 8 years ago

@tjuerges : There is a pending task of creating a contributions area and merge all the contrib code that is out there (#20). Ideally your code should go there. In the meantime I think it might be quicker if you send the tarball directly to Marco and Jorge.

tjuerges commented 8 years ago

@moraklein OK, I'll do that.

Edit: I have just sent an email to @javarias and @marco-buttu with the non-blocking client code example in C++.

tjuerges commented 8 years ago

@marco-buttu Did you get a chance to translate the code to Python? If so, it would be very useful to have the source code here in the repo.

marco-buttu commented 8 years ago

@tjuerges I did not, it is still pending in my queue. For sure I will put the code here