◐ Shell
clean mode source ↗

gh-120161: Fix a Crash in the _datetime Module by ericsnowcurrently · Pull Request #120182 · python/cpython

added 4 commits

June 6, 2024 17:21

sobolevn

@ericsnowcurrently

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Jun 14, 2024
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>

ericsnowcurrently added a commit that referenced this pull request

Jun 14, 2024
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>

This was referenced

Jun 14, 2024

ericsnowcurrently added a commit that referenced this pull request

Jun 17, 2024
…nterp_count (gh-120529)

gh-120182 added new global state (interp_count), but didn't add thread-safety for it.  This change eliminates the possible race.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Jun 17, 2024
…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>

ericsnowcurrently added a commit that referenced this pull request

Jun 17, 2024
…es[i].interp_count (gh-120657)

gh-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, AKA gh-120529)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>

mrahtz pushed a commit to mrahtz/cpython that referenced this pull request

Jun 30, 2024
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.

mrahtz pushed a commit to mrahtz/cpython that referenced this pull request

Jun 30, 2024
…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.

noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request

Jul 11, 2024
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.

noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request

Jul 11, 2024
…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.

estyxx pushed a commit to estyxx/cpython that referenced this pull request

Jul 17, 2024
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.

estyxx pushed a commit to estyxx/cpython that referenced this pull request

Jul 17, 2024
…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.