New GitHub issue #118608 from neonene:<br>

<hr>

<pre>
# Crash report

### What happened?

Example on Windows (debug build):

```py
# Taken from _ctypes issue: #116467
import subprocess
program = r"PCbuild\amd64\_testembed_d.exe"
cmd = [program, "test_repeated_init_exec", "import datetime"]   # or _datetime

for i in range(1, 11):
    print(f"   == Process #{i} ===")
    proc = subprocess.run(cmd)
    exitcode = proc.returncode
    print(f"=> exitcode {exitcode}")
    if exitcode:
        break
    print()
```


Output (7bbce383fa207ad83a6221bf70678c75c3c92142: CI failures with a similar test):
```
Running Debug|x64 interpreter...
   == Process #1 ===
--- Loop #1 ---
--- Loop #2 ---
Assertion failed: PyUnicode_CheckExact(ep_key), file C:\a\Objects\dictobject.c, line 1119
=> exitcode 3
```


It is an expected error on a debug build, which comes form [`_PyUnicode_ClearInterned()`](https://github.com/python/cpython/blob/ea2c0016502472aa8baa3149050ada776d17a009/Objects/unicodeobject.c#L14679) in `unicodeobject.c` of the commit ea2c001:

```c
void
_PyUnicode_ClearInterned(PyInterpreterState *interp)
{
    ...
    /* TODO:
     * Currently, the runtime is not able to guarantee that it can exit without
     * allocations that carry over to a future initialization of Python within
     * the same process. i.e:
 *   ./python -X showrefcount -c 'import itertools'
     *   [237 refs, 237 blocks]
     *
     * Therefore, this should remain disabled for until there is a strict guarantee
     * that no memory will be left after `Py_Finalize`.
     */
#ifdef Py_DEBUG
    ...
```
Currently, release builds avoid the `datetime` crash by leaking all interned strings.  Both the crash and the leak should be fixed before shipping 3.13 final.

cc @vstinner


### CPython versions tested on:

3.12, CPython main branch

### Operating systems tested on:

Linux, macOS, Windows

### Output from running 'python -VV' on the command line:

_No response_
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/118608">View on GitHub</a>
<p>Labels: type-crash</p>
<p>Assignee: </p>