pypy 的字典是线程安全的吗?

Are dict thread-safe with pypy?

在 CPython 中,内置操作似乎是原子的和线程安全的,根据:https://docs.python.org/3/glossary.html#term-global-interpreter-lock

This simplifies the CPython implementation by making the object model (including critical built-in types such as dict) implicitly safe against concurrent access.

但是我找不到 Pypy 的任何信息:https://doc.pypy.org/en/latest/cpython_differences.html

其他 Whosebug answer 指出 PyPy 行为 可能 不同,但不清楚是否确实如此。

This all makes the assumption you are using CPython; Jython, IronPython, Pypy and other python implementations may make different decisions on when to switch threads.

Pypy 字典(和其他内置的)线程安全吗?还是不是?

根据 this question in the FAQ,PyPy 确实有一个 GIL。这应该可以防止并发访问任何类型的变量;因为实际上一次只有一个线程可以做任何事情。

Yes, PyPy has a GIL. Removing the GIL is very hard.