-
Notifications
You must be signed in to change notification settings - Fork 193
SG-40348: Fix print crashing when called from non-main thread; add warning for other mu commands #907
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
base: main
Are you sure you want to change the base?
Conversation
…ed cases (mu isn't thread safe) Signed-off-by: Patrick Bergeron <[email protected]>
Signed-off-by: Patrick Bergeron <[email protected]>
Signed-off-by: Patrick Bergeron <[email protected]>
Signed-off-by: Patrick Bergeron <[email protected]>
Signed-off-by: Patrick Bergeron <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(apart from the unused prefix which could be removed I think)
Thanks @pbergeron-adsk, I think this is a bug I've been trying to track down for ages. I have been getting random crashes if calling print from a python thread and thought it might be something like this. |
Signed-off-by: Patrick Bergeron <[email protected]>
No problem! |
Note: I will bypass view testing because this is an intermittent bug. |
Summarize your change.
Remove redirecting of python's print() command to mu's print().
Describe the reason for the change.
When we're running live review with debug traces on, we get a ton of stuff in the console (as expected) but also sometimes RV mysteriously crashes. It crashes with the message "Unexpected State" (but may crash elsewhere in mu-ish related handlers - it may crash with "bus error", or "segmentation fault")
This "Unexpected State" message is printed from the Mu garbage collector, which gets into an invalid state, because Live Review is running multiple threads, and Mu isn't thread safe.
But what does calling print() from python have to do Mu's garbage collector? Well, it's because when we issue a python print() statement, it's actually redirected to Mu's print() command, which calls the garbage collector (again, not thread safe), and (sometimes) crashes, but 100% crashes if you let it live review run long enough with print statements.
(The code that redirects python's print() to Mu's print() is in rv_commands_setup.py)
We looked into the possibility of just removing the redirection of python print, but, this is not an option since we need to show print statements into the RV console.
As an alternative, we instead detect mu being called from a non-main thread, and if so, prints out a warning message (see screenshot) that Mu isn't thread safe and that this should not be allowed.
Nevertheless, we will special-case "print()" being called from any thread, because it's often used to print traces to debug python stuff (even multi-threaded python stuff). However, for print(), we don't let the mu code execute. We call cout() directly via a helper function.
Describe what you have tested and on which operating system.
Tested on macOS, but the problem appears on any OS.
Add a list of changes, and note any that might need special attention during the review.
If possible, provide screenshots.
See that we detect an unsafe print() from python, and that the unsafe print (with a prefix) appears both in the console and in the terminal.
See that other mu commands (like sendInternalEvent) are detected in the wrong thread and a warning appears both in the console and in the terminal.