Event channel not responding inside QT application

Dear all,

I write you to ask help on a error I am getting when subscribing device proxies to Tango events inside a Qt application.
I try to describe what I am doing. I have a QWidget in which I create a class (derived from QObject) that creates Tango device proxies and subscribes to events defined in given Tango servers with callback model. Proxy creation and event subscription is not done in the main GUI widget thread but in a QThread. The error I get in the callback is the following:


reason=API_EventTimeout
desc=Event channel is not responding anymore, maybe the server or event system is down
origin=EventConsumer::KeepAliveThread()

I have seen from other posts that this error could be caused by a wrong TANGO_HOST or by a blocking callback preventing event heartbeat. I provide below some simplified code sketch and details to help you.


=== MyClass class ===
class MyClass : public QObject {
  Q_OBJECT
  
  MyClass(EventCB* cb)
    : m_eventCB(cb)
  {
    //…      
  }

  public slots:
    void Run()
    {
       //Init dev proxies and subscribe to events
       //… proxy->subscribe_event(attr_name,evt_type,m_eventCB)
    }

  protected:
    std::vector<Tango::DeviceProxy*> m_proxies;//list of proxies
    std::vector<std::vector<std::string>> m_subscribed_attrs;//list of subscribed attrs per proxy
    EventCB* m_eventCB;//event callback
    
};

=== MyWidget class ===
class MyWidget : public QWidget {
  QObject

  MyWidget(QWidget *parent = 0)
  {
    //Create widget objects
    m_eventCB= new EventCB;
    m_myClass= new MyClass(m_eventCB);
    m_thread= new QThread;

    //Connect thread start with object action
    connect(m_thread, SIGNAL(started()), m_myClass, SLOT(Run()), Qt::QueuedConnection);
	
    //Start thread
    m_myClass->moveToThread(m_thread);
    m_thread->start();
  } 

  protected:
    EventCB* m_eventCB;
    MyClass* m_myClass;
    QThread* m_thread;
};

I am using Tango version 9.2.5a (zmq 4.0.8, omniorb 4.2.1) on Ubuntu 16.04 LTS. TANGO_HOST is set to my laptop hostname (i.e. TANGO_HOST=riggi-tpt460:10000). I have 4 proxies with ~50 subscribed attributes in total. Polling periods ranges from 100 ms (few attributes) to 1000/3000 ms (the majority). I am subscribing to CHANGE events only.
I have performed some tests to understand more. For example, if I move the proxy creation and subscription part in a standalone Tango server for testing I do not get the error. I do not notice the error if I significantly reduce the number of attributes. I suspect I am doing something wrong, probably inconsistent with the QT event loop.

Do you have any hints on what I can try to do to understand the error?

Many thanks for your help,

Cheers,

Simone
****************************************************************
Simone Riggi
INAF, Osservatorio Astrofisico di Catania
Via S. Sofia 78
95123, Catania - Italy
phone: +39 095 7332 extension 282
e-mail: simone.riggi@gmail.com,
sriggi@oact.inaf.it
skype: simone.riggi
****************************************************************
Edited 5 years ago
Hello Simone.
It has been a Tango flaw for a long time.

Within your Run method, be sure to place this line of code


omni_thread::ensure_self se;

This will probably address your issue.

If your need to integrate Tango and Qt is not sporadic, consider using the QTango library (or, better, the forthcoming cumbia library), that provides a multi threaded framework to work with Tango and Qt.

Best regards.

Giacomo.
Hi Giacomo,

many thanks. I have tried your solution and it seems that the errors went away.
I will have a look at QTango & cumbia library to go beyond these QT+Tango tests.

Many thanks!

Simone
****************************************************************
Simone Riggi
INAF, Osservatorio Astrofisico di Catania
Via S. Sofia 78
95123, Catania - Italy
phone: +39 095 7332 extension 282
e-mail: simone.riggi@gmail.com,
sriggi@oact.inaf.it
skype: simone.riggi
****************************************************************
Dear all,

just to add that the errors was documented in this ticket https://sourceforge.net/p/tango-cs/bugs/833/. I missed that, so thanks again Giacomo.

For people seeing the post in the future, at the end I did the following in the QT example reported above:

1) Subclass QThread and override QThread::run() method in this way:


void MyThread::run()
{
  //Suggested fix
  omni_thread::ensure_self se; 

  //Start the QT event loop
  exec();
}

2) Use MyThread in place of QThread in the example reported above.

Seems it is working now.

Cheers,

Simone
****************************************************************
Simone Riggi
INAF, Osservatorio Astrofisico di Catania
Via S. Sofia 78
95123, Catania - Italy
phone: +39 095 7332 extension 282
e-mail: simone.riggi@gmail.com,
sriggi@oact.inaf.it
skype: simone.riggi
****************************************************************
Hi,

it's just came to my mind. What about pytango and pyqt (or taurus). Do we have a similar workaround for the python case?
In principle it should be the same. Do we have a similar pytango `omni_thread::ensure_self se;` variable.
In python I haven't seen this error (except from taurus but I hope it was missing tangohost definition problem ).

Best regards,
Jan
 
Register or login to create to post a reply.