-
Notifications
You must be signed in to change notification settings - Fork 87
Add is_alive method to CxxQtThread #984
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
Conversation
Hi @akiselev , thank you for taking the time to create this PR! overall I think the If you want to check e.g. this: if thread.is_alive() {
thread.queue(...).unwrap()
} May panic and crash your program. The reason for this is that the CxxQtThread does not have ownership of the QObject, it is only a handle to the thread the QObject lives in. So ideally you should really prefer just using.
if you want to avoid crashing your application in that case. If however, you want to use
Then it's very much a good and convenient API. So really you can only know for certain whether a QObject has already been destroyed, not whether it's still alive, as it may be destroyed at any point. |
6ea283d
to
8ed43ce
Compare
I renamed the method to |
8ed43ce
to
99e336e
Compare
Hi @akiselev , Thank you for the update to the PR. In case you have issues with the script, I can run it as well, just let me know. |
Updated |
Looks there there is another case of a test needing updating :-) Note you can run |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #984 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 71 71
Lines 11928 11953 +25
=========================================
+ Hits 11928 11953 +25 ☔ View full report in Codecov by Sentry. |
3c686a8
to
163c9ad
Compare
I updated the tests, so they hopefully pass CI now. |
- Implement is_destroyed method for CxxQtThread to check if associated QObject has been destroyed - Add cxxQtThreadIsDestroyed function in C++ header - Update Rust trait and implementation for Threading - Add documentation explaining usage and potential race conditions - Modify code generation to include new method in FFI layer
163c9ad
to
9be9362
Compare
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 :-)
Great to see this finally merged. Thank you @akiselev for your contribution! |
When combining async Rust channels and QT objects, it's really easy to end up in a situation where a message is received on the channel after the
QObject
has already been destroyed, causingCxxQtThread::queue
to throw an exception. This PR introduces anis_alive()
function to check the handle if it's been invalidated.