-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
gh-120161: Fix a Crash in the _datetime Module #120182
gh-120161: Fix a Crash in the _datetime Module #120182
Conversation
FYI, I'm planning on merging this Friday, barring any feedback. |
|
||
with self.subTest('complex'): | ||
script = textwrap.dedent(""" | ||
import asyncio |
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.
I would separate this test into its own method, it imports asyncio
. Which means that it needs @requires_working_socket()
decorator
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.
Btw, why does it need asyncio
? 🤔
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.
Because of the original issue (the snippet is taken almost verbatim).
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.
Importing asyncio
on its own is not enough to be a problem. I was able to verify that it works fine on a WASI build (where @requires_working_socket()
would skip). This is also verified by the WASI CI check passing. Unless there is another reason to do so, I'd rather not add that decorator.
@@ -6781,6 +6782,47 @@ def test_datetime_from_timestamp(self): | |||
self.assertEqual(dt_orig, dt_rt) | |||
|
|||
|
|||
class ExtensionModuleTests(unittest.TestCase): |
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.
@cpython_only
?
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.
We could, but currently there's mostly no need. If the extension module ("_datetime") doesn't exist then the "fast" version of the test is never created, and the pure-Python version of the test already always skips. (See Lib/test/test_datetime.py.) Also note that @cpython_only
would mean the test wouldn't be run for Python implementations that do provide a _datetime
accelerator module.
All that said, I don't see any harm with adding @cpython_only
on the new test method. I would certainly only expect it to fail on CPython. Thanks for bringing this up.
Thanks @ericsnowcurrently for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
In pythongh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for _datetime, I have applied a similar approach here. Also, credit goes to @mgorny and @neonene for the new tests. FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach with a future change on the main branch. (cherry picked from commit b2e71ff) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
GH-120518 is a backport of this pull request to the 3.13 branch. |
In gh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for _datetime, I have applied a similar approach here. Also, credit goes to @mgorny and @neonene for the new tests. FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach with a future change on the main branch. (cherry picked from commit b2e71ff, AKA gh-120182) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Looks like this broke some buildbots:
|
See gh-120524. |
…s[i].interp_count (pythongh-120529) pythongh-120182 added new global state (interp_count), but didn't add thread-safety for it. This change eliminates the possible race. (cherry picked from commit 2c66318) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
In pythongh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for _datetime, I have applied a similar approach here. Also, credit goes to @mgorny and @neonene for the new tests. FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach with a future change on the main branch.
…s[i].interp_count (pythongh-120529) pythongh-120182 added new global state (interp_count), but didn't add thread-safety for it. This change eliminates the possible race.
In pythongh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for _datetime, I have applied a similar approach here. Also, credit goes to @mgorny and @neonene for the new tests. FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach with a future change on the main branch.
…s[i].interp_count (pythongh-120529) pythongh-120182 added new global state (interp_count), but didn't add thread-safety for it. This change eliminates the possible race.
In pythongh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for _datetime, I have applied a similar approach here. Also, credit goes to @mgorny and @neonene for the new tests. FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach with a future change on the main branch.
…s[i].interp_count (pythongh-120529) pythongh-120182 added new global state (interp_count), but didn't add thread-safety for it. This change eliminates the possible race.
In gh-120009 I used an atexit hook to finalize the
_datetime
module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for_datetime
, I applied a similar approach here.Also, credit goes to @mgorny and @neonene for the new tests.
FYI, I'd like to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach on main after this is merged.
Objects/typeobject.c:143: managed_static_type_index_get: Assertion
managed_static_type_index_is_set(self)' failed.` in 3.13.0b2+, with freezegun #120161