-
Notifications
You must be signed in to change notification settings - Fork 63
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
BSK not yet compatible with python 3.12 #765
Comments
I suspected the segfault under python3.12 was related to how SysModel is set up in SWIG separately for I'm not actively working on python3.12 support, but if anyone is, I'm sharing this snippet in case it is useful.
|
Thanks for sharing your insight @sassy-asjp . |
I did a bit more reading and noticed https://stackoverflow.com/questions/78200321/python3-12-c-api-segfaults-with-openmp which seemed similar to the segfault we get. The director feature in SWIG likely is and was not handling the GIL correctly, which was revealed by GIL changes in python3.12. I tried changing the name of The fix has to be in SWIG since it's in the auto-generated code using the director feature. I think my original hunch was off base, and just happened to fix the segfault by breaking director feature entirely, causing the problematic code sections to never be reached in the first place. |
Thanks for the additional insight @sassy-asjp! |
It seems like the problem is directors AND threads. I hacked out the thread functionality and this diff passes all tests though isn't something we can merge.
I guess moving forward there are really two courses of action:
I'll see if I can find some time to create a minimal example showing the bug and post it to my bug ticket with SWIG, but no one has said anything on my ticket since I opened it so idk what the timeline on fixing the SWIG bug would be. |
howdy @sassy-asjp , thanks for the great update. This certainly helps narrow down what could be going on with Python 3.12 and BSK. I did try running the fastest SWIG 4.3 and it didn't make a difference. Their release notes claim to be supporting Python 3.12 and the in development 3.13 at this point. Knowing that the issue is with the multi-threading is great to know. To paraphrase your message above, you don't see anything wrong with the code we are using, there appears to be an issue with SWIG itself. If you come across a work-around idea let me know. I didn't write this multi-threading code, but I'm glad to reach out to him to get his input and support. At this point we might wait and see if the SWIG community responds to your bug report? |
I poked around trying to manually take the Python GIL before potential director calls, and realized that we have been using multithreading incorrectly in a subtle way. SWIG modules were built without multithreading feature, which means that SWIG will hold onto the Python GIL through the entire native procedure call. I'm not sure what the original justification was, or whether it was a mistake, but multithreading feature adds extra synchronization code which can reduce performance and might have seemed unnecessary. Basilisk's use of multithreading is only for multithreaded computation (not waiting on disk, etc.) and none of the code messes with the GIL (no risk of deadlock). This originally worked for those reasons, however changes in Python 3.12 likely to support the per interpreter GIL feature or GIL disabled builds. I turned on the threads feature on the relevant modules and it seems to work. |
Describe your use case
Python 3.12 is not yet supported. Need to work out updates to make Basilisk compatible with 3.12 and retain prior python compatibility.
The text was updated successfully, but these errors were encountered: