[mythtv] mythfrontend on ubuntu 17.04 testing X11 ICE problems

roger roger at beardandsandals.co.uk
Wed Feb 8 11:55:47 UTC 2017



On 08/02/17 01:12, Roger James wrote:
> On 7 February 2017 9:01:02 pm Mark Spieth <mark at digivation.com.au> wrote:
>
>> On 8/02/2017 7:01 AM, Roger James wrote:
>>> On 7 February 2017 6:05:19 pm Derek Atkins <warlord at MIT.EDU> wrote:
>>>
>>>>
>>>> One problem with this patch is that it will spin the CPU for the
>>>> wolReconnect idle time, which isn't very nice.
>>>>
>>>
>>> I agree that spinning isn't nice. But not pumping the event loop is
>>> worse. A sleep(1) in the loop would improve things.
>>>
>> The correct Qt way is to use a QTimer and register/call a slot to
>> continue the processing after the time is up in another function. You
>> need to think event programming. Let the main loop of the thread do the
>> event dispatching. Blocking is bad even this way.
>> HTH
>> Mark
>
> Agreed. That is correct way. Please read the start of this thread. 
> This is a simple fix for anyone who wants to try it. Yes it wastes CPU 
> cycles. But sleeping the main thread in mythfrontend just means that 
> nothing will happen.
>
> Paul has put a more GUI friendly startup window in master. But that 
> will not appear until 2.9.
>
> R.
>
> Roger
>
Here is a final version of the patch. Most of the times this piece of 
the code is called the gui is not on the screen. So the sleep can be 
anything from 1 second up.  However it should be less the the 90 second 
timer that is effectively running in the X session manager since the 
QCoreApplication has been instantiated. I disabled the processing of 
user interaction events for safety reasons feel free to try with 
QEventLoop::AllEvents.

Another fix for the XSM problem would to arrange for the 
QCoreApplication to be created after OpenDatabase has been called, but 
that is much more complex.

I have raised a bug on Qt for this. I think that Qt should set their own 
ICE IO error handler and not just let the default one crash out of the 
program on an exit(1). But they may well say, write your application 
properly :-)


index 7ad204a..bdeb10d 100644
--- a/mythtv/libs/libmythbase/mythdbcon.cpp
+++ b/mythtv/libs/libmythbase/mythdbcon.cpp
@@ -175,7 +175,12 @@ bool MSqlDatabase::OpenDatabase(bool skipdb)
                              .arg(m_dbparms.wolCommand));
                  }

-                sleep(m_dbparms.wolReconnect);
+                QTime sleepTime = 
QTime::currentTime().addSecs(m_dbparms.wolReconnect);
+                while (QTime::currentTime() < sleepTime)
+                {
+ QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 100);
+                    sleep(1); // Must not be longer than the X session 
manager save session timeout (usually 90 seconds).
+                }
                  connected = m_db.open();
              }

Roger


More information about the mythtv-dev mailing list