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 PyExt error handling #7042

Merged
merged 1 commit into from Sep 22, 2022
Merged

Fix PyExt error handling #7042

merged 1 commit into from Sep 22, 2022

Conversation

steven-johnson
Copy link
Contributor

The current PythonExtensionGen code attempts to provide verbose error (exception) messages by overriding halide_error and saving the message in a thread_local. This isn't safe or correct, however, and (in general) is wrong for any Halide code using multiple threads. #6994 proposes ways to mitigate this (and there are experiments in place to implement it), but unless/until those enhancements land, we can't leave the code in its current state. So:

  • Don't try to save the text at all.
  • Optionally log the text to stderr.
  • Just throw an exception with the numeric error code. This is suboptimal, but better than the existing usually-incorrect-message behavior.
  • Bonus: wrap both the error and print overloads with PyGILState_Ensure(), as we are supposed to, to ensure we don't die.

The current PythonExtensionGen code attempts to provide verbose error (exception) messages by overriding halide_error and saving the message in a thread_local. This isn't safe or correct, however, and (in general) is wrong for any Halide code using multiple threads. #6994 proposes ways to mitigate this (and there are experiments in place to implement it), but unless/until those enhancements land, we can't leave the code in its current state. So:
- Don't try to save the text at all.
- Optionally log the text to stderr.
- Just throw an exception with the numeric error code. This is suboptimal, but better than the existing usually-incorrect-message behavior.
- Bonus: wrap both the error and print overloads with `PyGILState_Ensure()`, as we are supposed to, to ensure we don't die.
@steven-johnson steven-johnson merged commit 7286ec3 into main Sep 22, 2022
@steven-johnson steven-johnson deleted the srj/pyext-err-handling branch September 22, 2022 17:07
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
The current PythonExtensionGen code attempts to provide verbose error (exception) messages by overriding halide_error and saving the message in a thread_local. This isn't safe or correct, however, and (in general) is wrong for any Halide code using multiple threads. halide#6994 proposes ways to mitigate this (and there are experiments in place to implement it), but unless/until those enhancements land, we can't leave the code in its current state. So:
- Don't try to save the text at all.
- Optionally log the text to stderr.
- Just throw an exception with the numeric error code. This is suboptimal, but better than the existing usually-incorrect-message behavior.
- Bonus: wrap both the error and print overloads with `PyGILState_Ensure()`, as we are supposed to, to ensure we don't die.
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.

None yet

2 participants