Overriding QThread.run and calling the default implementation

Giuseppe Corbelli corbelligiuseppe at mesdan.it
Wed Jul 7 08:55:30 BST 2021

On 7/7/21 2:03 AM, Maurizio Berti wrote:
> Il giorno mar 6 lug 2021 alle ore 10:40 Giuseppe Corbelli 
> <corbelligiuseppe at mesdan.it <mailto:corbelligiuseppe at mesdan.it>> ha scritto:
>     First let's note that there are a few threads running by default. I
>     added a setObjectName() to the worker thread before run() so that it's
>     easily spottable in GDB.
>     * Worker thread is running QEventLoop::exec()
>     * QDBusConnection, assume started automatically by Qt
>     (QEventLoop::exec())
>     * QXcbEventQueue (xcb_wait_for_event()) defined in the Qt XCB platform
>     plugin, assume started automatically by Qt
>     * 4 threads python:disk$0 to python:disk$4 waiting on a futex [1]
>     started by QXcbWindow::create() (why? did not dig the details)
>     * Main Python thread
> That's interesting.
> So, actually, there's also a QDBus thread that's started with *any* new 
> QApplication? Or is it just for any UI based application started on a 
> DBus based system?

As far as I can tell it's just for GUI applications as it is related to 
accessibility (see QAccessible class)

The DBus connection is started with the first QAbstractButton::setText() 
It calls:

QDBusConnection::sessionBus() uses a static
class QDBusConnectionManager : public QDaemonThread

which explains why a new thread is spawned.

> Be aware, the above questions might be nonsensical: unfortunately my 
> knowledge of deep-level programming is close to none, so I might be 
> saying a "corbelleria" ;-)
> Would you care to provide the steps you did to get the above? I do have 
> gdb, but I only used it a few times in the past and only under guidance.

gdb --args python test_thread.py

b pthread_create

It will break on pthread_create().
Use 'c' to continue and 'info threads' to see what's the name of the 
thread just created. Once you get the QDBusConnection thread just select 
it with 'thread N' and 'bt full' will show the backtrace (YMMV depending 
on symbols availability).

Giuseppe Corbelli

More information about the PyQt mailing list