Repository navigation
Correct threading usage in vendored AWB code - #249
Conversation
0cee90e to
19473d4
Compare
|
@edan-bainglass to clarify, what triggered this PR? Do you think this will solve the issue you saw with the kernels not being shutdown? If so, could you open an issue and describe how it can be deterministically re-produced?
I am not fully following the changes here, will need to take a closer look. But I would expect that if we simply mark the thread as daemonic (as you're doing in this PR) it should not block the kernel shutdown? |
I've opened an issue here - aiidalab/aiidalab#538. I'll add an MRE there soon. But yes, the suggestion, and implementation here, is to make these threads 🔥daemonic🔥 Note that regarding what was discussed the past few days, the primary offender was appmode (as suspected by @yakutovicha 😇). See issue there. This change alone takes care of much of the recently experienced issues. The remaining fixes (this PR, and similar ones on AWB and the QE app) aim to cover our backs w.r.t "bad" thread usage. |
| self._monitor_thread_stop.clear() | ||
| self._monitor_thread = threading.Thread( | ||
| target=self._monitor_process, args=(process_uuid,) | ||
| target=self._monitor_process, args=(process_uuid,), daemon=True |
There was a problem hiding this comment.
Making the thread daemonic so that it does not hold up a kernel marked for termination
|
@cpignedoli please review 🙏 |
There was a problem hiding this comment.
Thanks, Edan! I reviewed 19473d4 with Codex assistance. The change looks good for the stated scope. Independent probes confirmed actual polling, prompt stop while waiting, restart, and normal Python exit with each daemon worker; the exact base remained waiting on those workers.
One small, non-blocking test suggestion: call refreshed.clear() immediately after constructing ProcessListWidget and before start_autoupdate(). Construction already calls update(), so the current refreshed.wait() also passes when the background worker never refreshes. I confirmed this with a worker that only waits for the stop event.
The two new tests passed locally with --noconftest (the global PostgreSQL fixture setup was unavailable), along with 12 additional probes. CI is green, including the Chrome and Firefox notebook checks. The documented scope around daemon shutdown and explicit polling cleanup is appropriate. Looks good to me!
This PR modifies two threading issues that can hang a kernel marked for shutdown.
The old loop refreshed immediately, then slept for 30 seconds. It had no way to stop:
The new loop waits on a threading.Event:
wait()returnsFalsewhen the interval expires, so the table refreshes and the loop waits again. Whenstop_autoupdate()sets the event,wait()returnsTrueimmediately and the loop exits - no further waiting.The first refresh now occurs after one interval, not immediately. That’s okay here because the widget already calls
update()during construction. Closing a tab does not callstop_autoupdate()automatically. The daemon flag separately ensures this thread cannot hold up kernel shutdown.Partially addresses aiidalab/aiidalab#538