Menu

#709 read_attribute(SPECTRUM) returns None instead of empty array

open
PyTango
5
2016-02-02
2015-03-13
Sergi Rubio
No

Many attribute callbacks expect read_attibute(SPECTRUM) to return an array type; e.g. calling standard python methods like len(attr.value)

If the read attribute is empty, PyTango 8* is returning None instead; it is causing exceptions in the code. Thus, some attributes that are ok but just empty are not being properly displayed.

I see than the error can be bypassed using dim_x to check for array lenght. But, is this behavior the expected one or is this a bug?

Discussion

  • Tiago Coutinho

    Tiago Coutinho - 2015-05-11

    good question.
    Today in C++, the client would throw an exception API_EmptyDeviceAttribute.
    In PyTango this exception is handled by setting:
    .value = None
    .is_empty = True

    In Java (behavior from Jive) it seems it sets .value = []

    We started discussing in the kernel team on how to handle it. We have to take into account backward compatibility so it needs some thinking.

    We will keep you informed.

    For (Py)Tango 8 I suggest that you code it this way:

    v = device.read_attribute("my_spectrum_attr")
    if v.is_empty:
      v.value = []
    
     
  • Tiago Coutinho

    Tiago Coutinho - 2015-05-11
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,3 @@
    -
     Many attribute callbacks expect read_attibute(SPECTRUM) to return an array type; e.g. calling standard python methods like len(attr.value)
    
     If the read attribute is empty, PyTango 8* is returning None instead; it is causing exceptions in the code. Thus, some attributes that are ok but just empty are not being properly displayed.
    
    • assigned_to: Tiago Coutinho
     
  • Tiago Coutinho

    Tiago Coutinho - 2016-02-02

    It seems backward compatibility is an issue in Tango so I am afraid I cannot change the behavior. It was not forseen in tango that None != [] != exception which is a shame

     

Log in to post a comment.