Conchylicultor
Conchylicultor

Reputation: 5729

Are dict thread-safe with pypy?

In CPython, it seems that built-in operations are atomic and Thread safe, according to: 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.

However I couldn't find any information for Pypy: https://doc.pypy.org/en/latest/cpython_differences.html.

Other stackoverflow answer point that PyPy behavior may be different but it's not clear if it actually is.

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.

Are Pypy dict (and other built-in) thread safe ? Or not ?

Upvotes: 4

Views: 329

Answers (1)

Robert Kearns
Robert Kearns

Reputation: 1706

According to this question in the FAQ, PyPy does have a GIL. This should prevent any concurrent access to any type of variable; as only one thread can actually be doing anything at a time.

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

Upvotes: 2

Related Questions