Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing import of opentimelineio in Python 3.9 on Windows #1070

Conversation

JeanChristopheMorinPerso
Copy link
Member

@JeanChristopheMorinPerso JeanChristopheMorinPerso commented Sep 18, 2021

Relates to issue #828

I've been working on building wheels for Python 3.9 and I've been blocked by an issue where opentimelineio couldn't be imported once compiled. The issue only happened on Windows with Python 3.9 when the extension was statically linked (which is the default).

After a lot of back and forth and getting some help from @meshula and @LazyDodo, I was able to finally fix the problem.

The issue would manifest itself like this:

>>> import opentimelineio
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Users\jeanchristophemorin1\AppData\Roaming\Python\Python39\site-packages\opentimelineio\__init__.py", line 35, in <module>
    from . import (
  File "C:\Users\jeanchristophemorin1\AppData\Roaming\Python\Python39\site-packages\opentimelineio\exceptions.py", line 26, in <module>
    from . _otio import ( # noqa
ImportError: DLL load failed while importing _otio: A dynamic link library (DLL) initialization routine failed.

So _otio.pyd was properly found but failed to be initialized/loaded. Attaching a debugger would give this call stack:

>	python39_d.dll!PyErr_Occurred() Line 250	C
 	_otio_d.cp39-win_amd64.pyd!pybind11::arg_v::arg_v<std::string>(pybind11::arg && base, std::string && x, const char * descr) Line 1066	C++
 	_otio_d.cp39-win_amd64.pyd!pybind11::arg_v::arg_v<std::string>(const pybind11::arg & base, std::string && x, const char * descr) Line 1080	C++
 	_otio_d.cp39-win_amd64.pyd!pybind11::arg::operator=<std::string>(std::string && value) Line 1110	C++
 	_otio_d.cp39-win_amd64.pyd!`dynamic initializer for 'name_arg''() Line 126	C++

Somehow, CPython isn't happy with

static py::arg_v name_arg = ("name"_a = std::string());
static py::arg_v metadata_arg = ("metadata"_a = py::none());

in src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp. As my C/C++ knowledge is limited, I can't explain nor understand why it's causing a problem, but I found how to fix it.

Simply removing the static vars from the global scope and in lining them (Not sure if it's the right term, but it feel like it to me. Let me know if it's the wrong term) fixes the problem.

Note that CI for Python 3.9 will be added in a future PR. In the meantime, you can see a build in my fork: https://github.com/JeanChristopheMorinPerso/OpenTimelineIO/runs/3637946770?check_suite_focus=true.

…l static variables from src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp.
Copy link
Collaborator

@meshula meshula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wonderful, thanks so much for your perseverance on this difficult issue!

@meshula meshula merged commit 835fc5c into AcademySoftwareFoundation:master Sep 18, 2021
@JeanChristopheMorinPerso JeanChristopheMorinPerso deleted the python39_no_static_var branch September 21, 2021 01:01
@ssteinbach ssteinbach added this to the Public Beta 14 milestone Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants