unsubscribe_event exception

Dear all,
I'm working with PyTango 9.2.5 and I've noted that unsubscribe_event failure raises a KeyError exception and not an EventSystemFailed (as stated in the documentation).
This may cause problems in exception handling.
May be I'm doing something wrong.

Thanks in advance for any help

Hi Elisabetta

You haven't provided much info, so I'll take a guess. I see the docs do say it might throw EventSystemFailed, so we should probably add the KeyError as well.

If you're not just asking about the documentation, but want to know why you are getting the KeyError, one of the causes, would be if you are using different instances of the DeviceProxy. For example, if you subscribe for with instance A, and unsubscribe with instance B, that will fail. You must use the same instance to subscribe and unsubscribe. This type of error would look something like this (dp2 is a tango.DeviceProxy object):

In [18]: dp2.unsubscribe_event(1)
KeyError Traceback (most recent call last)
<ipython-input-18-44bf2988cd61> in <module>()
—-> 1 dp2.unsubscribe_event(1)

/usr/lib/python2.7/dist-packages/tango/green.pyc in greener(obj, *args, **kwargs)
193 green_mode = access('green_mode', None)
194 executor = get_object_executor(obj, green_mode)
–> 195 return executor.run(fn, args, kwargs, wait=wait, timeout=timeout)
197 return greener

/usr/lib/python2.7/dist-packages/tango/green.pyc in run(self, fn, args, kwargs, wait, timeout)
107 # Sychronous (no delegation)
108 if not self.asynchronous or not self.in_executor_context():
–> 109 return fn(*args, **kwargs)
110 # Asynchronous delegation
111 accessor = self.delegate(fn, *args, **kwargs)

/usr/lib/python2.7/dist-packages/tango/device_proxy.pyc in __DeviceProxy__unsubscribe_event(self, event_id)
1281 evt_info = se[event_id]
1282 except KeyError:
-> 1283 raise KeyError("This device proxy does not own this subscription " + str(event_id))
1284 del se[event_id]
1285 self._pending_unsubscribe[event_id] = evt_info[0], timestamp + _UNSUBSCRIBE_LIFETIME

KeyError: 'This device proxy does not own this subscription 1'

There would be a similar error if the ID used to unsubscribe was invalid.

If that is not the type of error you are seeing, please post more details.
Hi Anton,
thanks for the reply.
I'm trying to enforce my code adding more accurate exception handling. To test a part of the code I've tried to unsubscribe an invalid event, but no tango.DevFailed exception was raised but only KeyError.
I didn't understand why, I checked the documentation and ask to the forum to get confirm of this.
And I got it! smile


Glad to help. Thanks for pointing out the issue.
I have made a PR on pytango to update the docs. https://github.com/tango-controls/pytango/pull/293
Register or login to create to post a reply.