Fix failing import of opentimelineio in Python 3.9 on Windows #1070
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
So
_otio.pyd
was properly found but failed to be initialized/loaded. Attaching a debugger would give this call stack:Somehow, CPython isn't happy with
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.