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

Interrupt USB polling thread before threading shutdown #480

Merged
merged 1 commit into from
Oct 29, 2023

Conversation

whitequark
Copy link
Member

@whitequark whitequark commented Oct 29, 2023

WIP: requires libusb1 version bump after vpelletier/python-libusb1#90 is merged.

While performing USBContext.handleEvents() the poller thread is uninterruptible other than through libusb1 API. Since the Python runtime joins all non-daemon threads on threading shutdown it is necessary to interrupt the thread by calling the corresponding libusb1 function.

A seemingly obvious solution is to make the thread a daemon thread so that it is not joined on threading shutdown. Unfortunately this only makes the problem worse. All daemon threads are instantly killed, leaving a lock within libusb1 permanently taken, and causing a hang later when python-libusb1 objects are garbage collected.

Fixes #413.

@whitequark whitequark force-pushed the fix-hang-on-repl-exit branch 2 times, most recently from f612b81 to 364624a Compare October 29, 2023 03:32
@whitequark whitequark marked this pull request as ready for review October 29, 2023 03:32
While performing `USBContext.handleEvents()` the poller thread is
uninterruptible other than through libusb1 API. Since the Python runtime
joins all non-daemon threads on threading shutdown it is necessary to
interrupt the thread by calling the corresponding libusb1 function.

A seemingly obvious solution is to make the thread a daemon thread so
that it is not joined on threading shutdown. Unfortunately this only
makes the problem worse. All daemon threads are instantly killed on
shutdown, leaving a lock within libusb1 permanently taken, and causing
a hang later when python-libusb1 objects are garbage collected by
the main thread.

Fixes GlasgowEmbedded#413.
@whitequark whitequark added this pull request to the merge queue Oct 29, 2023
Merged via the queue into GlasgowEmbedded:main with commit 23f815f Oct 29, 2023
18 of 20 checks passed
@whitequark whitequark deleted the fix-hang-on-repl-exit branch October 29, 2023 03:46
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.

Calling exit() from script / REPL does not terminate glasgow
1 participant