Resolving an annoying PyQt Warning in OpenStackClient

Image by John Reed / Unsplash

I’ve recently been seeing the following warning when running openstack commands locally:

$ openstack server list -n -f yaml
QSocketNotifier: Can only be used with threads started with QThread
...

This made no sense: OSC doesn’t use Qt so why am I seeing errors related to this? I also was only seeing it on one host. What gives? Well it took me a while but it turned out this wasn’t due to OSC or even one of its direct dependencies: it was an indirect dependency, pyperclip. By exporting PYTHONPROFILEIMPORTTIME=1, I was able to figure out what import caused the error:

$ export PYTHONPROFILEIMPORTTIME=1
$ openstack server list -n -f yaml
import time: self [us] | cumulative | imported package
import time:       647 |        647 |   _io
...
import time:       160 |        345 |   osc_lib.command.commandmanager
import time:       280 |        280 |           _compat_pickle
import time:       227 |        227 |           _pickle
import time:        64 |         64 |               org
import time:        16 |         79 |             org.python
import time:        15 |         93 |           org.python.core
import time:       650 |       1248 |         pickle
import time:       523 |       1771 |       logging.handlers
import time:       161 |        161 |               wcwidth.table_wide
import time:       342 |        342 |               wcwidth.table_zero
import time:       129 |        129 |               wcwidth.unicode_versions
import time:       267 |        897 |             wcwidth.wcwidth
import time:       199 |       1096 |           wcwidth
import time:     12691 |      13786 |         cmd2.ansi
import time:       113 |        113 |           cmd2.constants
import time:      1116 |       1228 |         cmd2.argparse_custom
import time:       183 |        183 |             cmd2.exceptions
import time:       922 |        922 |             cmd2.utils
import time:       235 |       1340 |           cmd2.command_definition
import time:       955 |        955 |           cmd2.table_creator
import time:       404 |       2698 |         cmd2.argparse_completer
import time:       264 |        264 |           cmd
import time:       328 |        328 |             _sysconfigdata__linux_x86_64-linux-gnu
import time:      1251 |       1578 |           pydoc
import time:       133 |        133 |             codeop
import time:       181 |        314 |           code
import time:       151 |        151 |                 attr._compat
import time:       102 |        102 |                   attr._config
import time:       181 |        181 |                     attr.exceptions
import time:       107 |        287 |                   attr.setters
import time:      2597 |       2985 |                 attr._make
import time:       180 |       3315 |               attr.converters
import time:       132 |        132 |               attr.filters
import time:      3697 |       3697 |               attr.validators
import time:       161 |        161 |               attr._cmp
import time:       139 |        139 |               attr._funcs
import time:       573 |        573 |               attr._version_info
import time:       142 |        142 |               attr._next_gen
import time:       285 |       8439 |             attr
import time:       264 |        264 |               shlex
import time:      3435 |       3698 |             cmd2.parsing
import time:      1509 |      13645 |           cmd2.plugin
import time:       364 |        364 |                 _ctypes
import time:       186 |        186 |                 ctypes._endian
import time:       589 |       1138 |               ctypes
import time:       306 |       1444 |             pyperclip
import time:        76 |         76 |             gtk
import time:        71 |         71 |             qtpy
import time:       220 |        220 |             PyQt5
import time:        54 |         54 |               qtpy
import time:        17 |         71 |             qtpy.QtWidgets
import time:       342 |        342 |               PyQt5.sip
import time:      6530 |       6530 |               PyQt5.QtCore
import time:      5953 |       5953 |               PyQt5.QtGui
import time:     14655 |      27478 |             PyQt5.QtWidgets
QSocketNotifier: Can only be used with threads started with QThread
...

As for why I wasn’t seeing this on other hosts: those other hosts didn’t have PyQT5 installed.

$ sudo dnf remove PyQt5
Dependencies resolved.
=====================================================================================================================================================================================================================
 Package                                                     Architecture                                 Version                                                Repository                                     Size
=====================================================================================================================================================================================================================
Removing:
 python3-qt5                                                 x86_64                                       5.15.6-3.fc36                                          @fedora                                       7.0 M
Removing dependent packages:
 krop                                                        noarch                                       0.5.1-13.fc36                                          @fedora                                       6.5 k
Removing unused dependencies:
 poppler-qt5                                                 x86_64                                       22.01.0-3.fc36                                         @fedora                                       632 k
 python-qt5-rpm-macros                                       noarch                                       5.15.6-3.fc36                                          @fedora                                       143
 python3-PyPDF2                                              noarch                                       1.26.0-19.fc36                                         @fedora                                       520 k
 python3-krop                                                noarch                                       0.5.1-13.fc36                                          @fedora                                       225 k
 python3-poppler-qt5                                         x86_64                                       21.1.0-5.fc36                                          @fedora                                       562 k
 python3-pyqt5-sip                                           x86_64                                       12.9.0-3.fc36                                          @fedora                                       154 k
 python3-qt5-base                                            x86_64                                       5.15.6-3.fc36                                          @fedora                                        17 M
 qt5-qtconnectivity                                          x86_64                                       5.15.3-1.fc36                                          @fedora                                       1.4 M

Transaction Summary
=====================================================================================================================================================================================================================
Remove  10 Packages

Freed space: 28 M
Is this ok [y/N]: y
...

I’d installed krop at some point and it had dragged in various Python dependencies as a result. The ultimate fix probably exists somewhere in pyperclip (or even PyQt5) but uninstalling things was enough to get rid of this annoying warning.

Hopefully Google finds this page in case anyone is similarly frustrated by this.

comments powered by Disqus