-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Allow the GIL to be enabled on the unix port, and add a CI job to test this configuration #17668
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
Allow the GIL to be enabled on the unix port, and add a CI job to test this configuration #17668
Conversation
Code size report:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #17668 +/- ##
=======================================
Coverage 98.37% 98.37%
=======================================
Files 171 171
Lines 22210 22210
=======================================
Hits 21849 21849
Misses 361 361 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
526493b
to
62f720f
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.
Changes look good to me. Suggest as part of this PR we also add some brief docs about the native emitter thread/scheduler starvation issue, and the sleep(0)
workaround. I think the appropriate place is the dot point list in reference/speed_python.rst
?
(While looking for that I also noticed that refernece/micropython.rst
doesn't document the native
annotation at all - it should probably have a short entry that links to the explanatory section in speed_python.rst
? I can submit this in a follow-up, though.)
62f720f
to
13aae9e
Compare
I've now added this in the last commit.
Yes, would be good to document bytecode/native/viper decorators in |
The unix port can now be built with the GIL enabled, by passing MICROPY_PY_THREAD_GIL=1 on the make command line. Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
The native emitter will not release/bounce the GIL when running code, so if it runs tight loops then no other threads get a chance to run (if the GIL is enabled). So for the thread tests, explicitly include a call to `time.sleep(0)` (or equivalent) to bounce the GIL and give other threads a chance to run. For some tests (eg `thread_coop.py`) the whole point of the test is to test that the GIL is correctly bounced. So for those cases force the use of the bytecode emitter for the busy functions. Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
13aae9e
to
677a0e0
Compare
Summary
Up until now, thread tests have only been run (under CI at least) on a small number of build configurations. PR #17655 enables the thread tests on a lot more of the existing builds, and this PR adds a new job which builds and tests the unix port with the GIL enabled.
(This PR builds on #17655 and includes all the commits from that PR.)
Running tests with the GIL enabled will help to test the esp32 port's threading implementation, which also uses the GIL.
Edit: updated some thread tests to add
time.sleep(0)
to the busy-wait loop, so that they pass when used with the native emitter.Testing
Will be tested by CI.
Edit: new CI job runs correctly, and takes 1 minute 55 seconds. It runs the thread tests in bytecode and native emitter mode.
Trade-offs and Alternatives
Adds a new CI job which adds to the CI time, but it should only be a couple of minutes, and run in parallel.