Skip to content

BUG: Importing pandas interferes with mutexes in unrelated modules. #59603

@alexcthomas

Description

@alexcthomas

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

#include <iostream>
#include <pybind11/pybind11.h>
#include <mutex>

namespace py = pybind11;

void create_mutex() {
    py::gil_scoped_release release;
    std::cout << "Creating mutex\n";
    std::mutex local_mutex;
    std::cout << "Mutex created\n";
    {
        std::cout << "Attempting to lock mutex\n";
        std::lock_guard<std::mutex> lock(local_mutex);
        std::cout << "Mutex locked and unlocked\n";
    }
    std::cout << "Exiting create_mutex\n";
}

PYBIND11_MODULE(TestModule, m) {
    m.doc() = "Test Module";
    m.def("create_mutex", &create_mutex, "Create mutex");
}

Issue Description

Creating a python module with the above code, then running it in python:

import pandas as pd
import TestModule as tm
tm.create_mutex()

crashes without error message after outputting:

Creating mutex
Mutex created
Attempting to lock mutex

The issue occurs whether the gil is released or not. (using pybind11::gil_scoped_acquire acquire;)

Expected Behavior

Should output this without crashing.

Creating mutex
Mutex created
Attempting to lock mutex
Mutex locked and unlocked
Exiting create_mutex

Removing the pandas import from the python allows it to do this.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.12.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : AMD64 Family 23 Model 49 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United Kingdom.1252

pandas : 2.2.2
numpy : 2.1.0
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : None
pip : 24.1.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 17.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
pybind11: : 2.13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBuildLibrary building on various platforms

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions