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

Per-thread exceptions #7251

Closed
wants to merge 2 commits into from
Closed

Conversation

dlech
Copy link
Sponsor Contributor

@dlech dlech commented May 11, 2021

This is a fix for #7026.

I have updated some old patches to the current master branch. We've been using this on the UNIX port for a over a year now. One thing I'm not sure about is what happens when both threads and the scheduler are enabled. Would it be possible for the scheduler run on a different thread and delay the pending exception on the main thread?

This moves mp_pending_exception from mp_state_vm_t to mp_state_thread_t.
This allows exceptions to be scheduled on a specific thread.

Signed-off-by: David Lechner <david@pybricks.com>
@dlech dlech force-pushed the per-thread-exception branch 4 times, most recently from ce3d730 to 791c6b7 Compare May 11, 2021 03:38
This introduces a new macro to get the main thread and uses it to ensure
that asynchronous exceptions such as KeyboardInterrupt (CTRL+C) are only
scheduled on the main thread. This is more deterministic than being
scheduled on a random thread and is more in line with CPython that only
allow signal handlers to run on the main thread.

Issue: micropython#7026
Signed-off-by: David Lechner <david@pybricks.com>
@dpgeorge
Copy link
Member

Thanks for this, it looks good to me, quite clean and straightforward.

One thing I'm not sure about is what happens when both threads and the scheduler are enabled. Would it be possible for the scheduler run on a different thread and delay the pending exception on the main thread?

Yes that's something that needs separate investigation. It will depend on whether the GIL is enabled or not.

Regardless of that, the change here makes a good step forward and resolves #7026. Merged in ca920f7 and 259d9b6

@dpgeorge dpgeorge closed this Jun 18, 2021
@dlech dlech deleted the per-thread-exception branch June 18, 2021 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants