Skip to content

Commit e1f8ab4

Browse files
committed
fix: gate asyncio import during init; disable it in cleanup CI to avoid early ssl load
PythonQt::init() unconditionally imported `asyncio`. On Python 3.12 this pulls in `asyncio.sslproto` -> `ssl` -> the `_ssl` C extension. In our "cleanup" test on Ubuntu 24.04 (with sanitizers and rapid finalize), that early `_ssl` load segfaulted inside import/teardown.
1 parent 43a3b9a commit e1f8ab4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ jobs:
8888
PYTHONDEVMODE=1 PYTHONASYNCIODEBUG=1 PYTHONWARNINGS=error PYTHONMALLOC=malloc_debug \
8989
UBSAN_OPTIONS="halt_on_error=1" ASAN_OPTIONS="detect_leaks=1:detect_stack_use_after_return=1:fast_unwind_on_malloc=0" \
9090
PYTHONQT_RUN_ONLY_CLEANUP_TESTS=1 \
91+
PYTHONQT_DISABLE_ASYNCIO=1 \
9192
make check TESTARGS="-platform minimal"
9293
9394
- name: Generate Wrappers

src/PythonQt.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,17 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName)
102102
}
103103

104104
#ifdef PY3K
105-
PythonQtObjectPtr asyncio;
106-
asyncio.setNewRef(PyImport_ImportModule("asyncio"));
107-
if (asyncio)
108-
{
109-
_self->_p->_pyEnsureFuture = asyncio.getVariable("ensure_future");
110-
_self->_p->_pyFutureClass = asyncio.getVariable("Future");
105+
// Import asyncio only when not explicitly disabled.
106+
// Importing asyncio on Py3.12+ pulls in ssl/_ssl; some environments/tests
107+
// want to avoid that during early embedded init.
108+
if (!qEnvironmentVariableIsSet("PYTHONQT_DISABLE_ASYNCIO")) {
109+
PythonQtObjectPtr asyncio;
110+
asyncio.setNewRef(PyImport_ImportModule("asyncio"));
111+
if (asyncio)
112+
{
113+
_self->_p->_pyEnsureFuture = asyncio.getVariable("ensure_future");
114+
_self->_p->_pyFutureClass = asyncio.getVariable("Future");
115+
}
111116
}
112117
#endif
113118

0 commit comments

Comments
 (0)