Last active
May 5, 2016 15:00
-
-
Save brickZA/8d411ce21aefc688a3cc70a08592c7dc to your computer and use it in GitHub Desktop.
Minimal test of tango events an file database using PyTango
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm trying to use a file database to run isolated unit tests. This is | |
essentially what https://github.com/vxgmichel/pytango-devicetest does behind the | |
scenes. The documentation from pytango-devicetest claims that: | |
Tango events are not supported by the --file execution mode. See the Tango | |
documentation for further information. | |
However, the Tango documentation says: | |
D.5.2 For release 8 and above | |
A new event system has been implemented starting with Tango release 8. With this | |
new event system, the CORBA Notification service is not needed any more. This | |
means that as soon as all clients using events from devices embedded in the | |
device server use Tango 8, it is not required to start any process other than | |
the device server and its clients. | |
Unfortunately, it seems that in practice the pytango-devicetest readme seems to | |
be accurate in spite of what the tango documentation says. It seems that events | |
don't work when a file database is used. | |
I'm not sure if I'm doing anything wrong, so I placed a minimal testcase in this | |
gist: https://gist.github.com/brickZA/8d411ce21aefc688a3cc70a08592c7dc | |
build info: | |
python -c "from PyTango.utils import info; print(info())" | |
PyTango 9.2.0 (9, 2, 0, 'b', 1) | |
PyTango compiled with: | |
Python : 2.7.6 | |
Numpy : 0.0.0 | |
Tango : 9.2.2 | |
Boost : 1.55.0 | |
PyTango runtime is: | |
Python : 2.7.6 | |
Numpy : None | |
Tango : 9.2.2 | |
Boost : 0.0.0 | |
PyTango running on: | |
('Linux', 'tango-test', '4.2.0-30-generic', '#36-Ubuntu SMP Fri Feb 26 00:58:07 UTC 2016', 'x86_64', 'x86_64') | |
Additional details: Built PyTango from pytango9 branch from github, and used | |
self-made tango .debs that were ported from the current debian packages to build | |
on Ubuntu 14.04. | |
Using the database we run the server as: | |
python PolledDS.py --register test/withdb/polled | |
python PolledDS.py polled | |
and client as: | |
python PolledDS_client.py 'test/withdb/polled' | |
This results in a regular stream of event updates: | |
event_type: change val: True time: 1462459184.51437 received_time: 1462459184.88911 | |
event_type: periodic val: True time: 1462459184.51437 received_time: 1462459184.92293 | |
event_type: periodic val: True time: 1462459185.51359 received_time: 1462459185.51384 | |
event_type: periodic val: True time: 1462459186.51388 received_time: 1462459186.51412 | |
event_type: periodic val: True time: 1462459187.51414 received_time: 1462459187.51431 | |
event_type: periodic val: True time: 1462459188.51441 received_time: 1462459188.51461 | |
event_type: periodic val: True time: 1462459189.51402 received_time: 1462459189.51462 | |
Running with a file database, we run the server as: | |
python PolledDS.py polled -ORBendPoint giop:tcp::12345 -file=tango.db | |
and client as: | |
python PolledDS_client.py 'localhost:12345/test/nodb/polled#dbase=no' | |
Then we get the initial event update, but after that, only: | |
2016-05-05 14:37:53,806 - root - ERROR - PolledDS_client - PolledDS_client.py : 36 - Exception while handling event, event_data: EventData[ | |
attr_name = 'tango://localhost:12345/test/nodb/polled/scalarbool#dbase=no' | |
attr_value = None | |
device = Polled(test/nodb/polled) | |
err = True | |
errors = (DevError(desc = 'Event channel is not responding anymore, maybe the server or event system is down', origin = 'EventConsumer::KeepAliveThread()', reason = 'API_EventTimeout', severity = PyTango._PyTango.ErrSeverity.ERR),) | |
event = 'change' | |
reception_date = TimeVal(tv_nsec = 0, tv_sec = 1462459073, tv_usec = 804448)] | |
Traceback (most recent call last): | |
File "PolledDS_client.py", line 29, in printer | |
value = attr_value.value | |
AttributeError: 'NoneType' object has no attribute 'value' | |
event_type: idl5_change val: True time: 1462459073.60559 received_time: 1462459073.80705 | |
2016-05-05 14:37:53,807 - root - ERROR - PolledDS_client - PolledDS_client.py : 36 - Exception while handling event, event_data: EventData[ | |
attr_name = 'tango://localhost:12345/test/nodb/polled/scalarbool#dbase=no' | |
attr_value = None | |
device = Polled(test/nodb/polled) | |
err = True | |
errors = (DevError(desc = 'Event channel is not responding anymore, maybe the server or event system is down', origin = 'EventConsumer::KeepAliveThread()', reason = 'API_EventTimeout', severity = PyTango._PyTango.ErrSeverity.ERR),) | |
event = 'periodic' | |
reception_date = TimeVal(tv_nsec = 0, tv_sec = 1462459073, tv_usec = 807174)] | |
Traceback (most recent call last): | |
File "PolledDS_client.py", line 29, in printer | |
value = attr_value.value | |
AttributeError: 'NoneType' object has no attribute 'value' | |
2016-05-05 14:38:03,813 - root - ERROR - PolledDS_client - PolledDS_client.py : 36 - Exception while handling event, event_data: EventData[ | |
attr_name = 'tango://localhost:12345/test/nodb/polled/scalarbool#dbase=no' | |
attr_value = None | |
device = Polled(test/nodb/polled) | |
err = True | |
errors = (DevError(desc = 'Event channel is not responding anymore, maybe the server or event system is down', origin = 'EventConsumer::KeepAliveThread()', reason = 'API_EventTimeout', severity = PyTango._PyTango.ErrSeverity.ERR),) | |
event = 'change' | |
reception_date = TimeVal(tv_nsec = 0, tv_sec = 1462459083, tv_usec = 813407)] | |
Traceback (most recent call last): | |
File "PolledDS_client.py", line 29, in printer | |
value = attr_value.value | |
AttributeError: 'NoneType' object has no attribute 'value' | |
event_type: idl5_change val: True time: 1462459083.60535 received_time: 1462459083.81440 | |
2016-05-05 14:38:03,814 - root - ERROR - PolledDS_client - PolledDS_client.py : 36 - Exception while handling event, event_data: EventData[ | |
attr_name = 'tango://localhost:12345/test/nodb/polled/scalarbool#dbase=no' | |
attr_value = None | |
device = Polled(test/nodb/polled) | |
err = True | |
errors = (DevError(desc = 'Event channel is not responding anymore, maybe the server or event system is down', origin = 'EventConsumer::KeepAliveThread()', reason = 'API_EventTimeout', severity = PyTango._PyTango.ErrSeverity.ERR),) | |
event = 'periodic' | |
reception_date = TimeVal(tv_nsec = 0, tv_sec = 1462459083, tv_usec = 814496)] | |
Traceback (most recent call last): | |
File "PolledDS_client.py", line 29, in printer | |
value = attr_value.value | |
AttributeError: 'NoneType' object has no attribute 'value' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import logging | |
from PyTango import Database, DbDevInfo | |
from PyTango import server as TS | |
class Polled(TS.Device): | |
__metaclass__ = TS.DeviceMeta | |
@TS.attribute(dtype='DevBoolean', | |
doc='An example scalar boolean attribute', polling_period=1000) | |
def ScalarBool(self): | |
return True | |
if __name__ == "__main__": | |
logging.basicConfig( | |
format='%(asctime)s - %(name)s - %(levelname)s - %(module)s - ' | |
'%(pathname)s : %(lineno)d - %(message)s', | |
level=logging.INFO) | |
if '--register' in sys.argv: | |
reg_ind = sys.argv.index('--register') | |
sys.argv.pop(reg_ind) | |
name = sys.argv.pop(reg_ind) | |
db = Database() | |
dev_info = DbDevInfo() | |
dev_info._class = 'Polled' | |
dev_info.server = 'PolledDS/polled' | |
dev_info.name = name | |
db.add_device(dev_info) | |
else: | |
TS.server_run([Polled]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
import logging | |
import PyTango | |
logger = logging.getLogger() | |
logging.basicConfig( | |
format='%(asctime)s - %(name)s - %(levelname)s - %(module)s - ' | |
'%(pathname)s : %(lineno)d - %(message)s', | |
level=logging.INFO) | |
#device_name = 'test/withdb/polled' | |
#device_name = 'localhost:12345/test/nodb/polled#dbase=no' | |
device_name = sys.argv[1] | |
td = PyTango.DeviceProxy(device_name) | |
attr_name = 'ScalarBool' | |
# Set up a listener | |
def printer(event_data): | |
# print event_data # Seems to be an PyTango.EventData instance | |
try: | |
event_type = event_data.event | |
attr_value = event_data.attr_value | |
value = attr_value.value | |
timestamp = attr_value.time.totime() | |
received_timestamp = event_data.reception_date.totime() | |
print 'event_type: {} val: {} time: {:.5f} received_time: {:.5f}'.format( | |
event_type, value, timestamp, received_timestamp) | |
except Exception: | |
logger.exception('Exception while handling event, event_data: {}' | |
.format(event_data)) | |
event_ids = dict(change=td.subscribe_event( | |
attr_name, PyTango.EventType.CHANGE_EVENT, printer), | |
periodic=td.subscribe_event( | |
attr_name, PyTango.EventType.PERIODIC_EVENT, printer)) | |
time.sleep(1000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PolledDS/polled/DEVICE/Polled: "test/nodb/polled" | |
############################################# | |
# CLASS Polled | |
# CLASS Polled attribute properties | |
# DEVICE test/nodb/polled properties | |
test/nodb/polled->polled_attr: scalarbool,\ | |
1000 | |
# DEVICE test/nodb/polled attribute properties | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment