5

This relates to previous questions regarding the GIL (Global Interpreter Lock) for Python on the Raspberry Pi. My question has to do with the new processor on the Pi 4 - does it still have the same restrictions as the Pi 3, where it cannot natively split a Python script into multiple cores?

This may be a fundamental misunderstanding on my part of the purpose of the GIL, but I was hoping maybe the Pi 4's new processor did not have this same restriction.

The Pi 4's new processor (Broadcom BCM2711) has four Arm Cortex A72 cores, whereas the Pi 3 had four Cortex A53 cores. They link to their preliminary datasheet here, but it doesn't seem to have much information on it.

Aside: There doesn't seem to be a Pi-4 tag, could someone please create it?

Ghanima
  • 15,855
  • 15
  • 61
  • 119

2 Answers2

8

GIL is a design specification of the Python language, rather than a limitation of the Raspberry Pi [1] (multiprocessing is possible in Python, often with only a few lines of code [2], but multithreading is generally not). The new processor will have no effect on the limitations associated with GIL.

KPM
  • 216
  • 1
  • 6
1

You can overcome the GIL limitation. The details are here and too long to copy into this post. The technology relies upon compiling some forms of Python code using the Just In Time compiler Numba.

In general compiled code called by the Python interpreter can release the GIL and execute on multiple threads at the same time. Libraries like NumPy and Pandas release the GIL automatically, so multithreading can be fairly efficient for Python code where NumPy and Pandas operations are the bulk of the computation time.

In other cases Numba is a solution. Though caveat emptor, since I haven't tried out Numba on a Pi 3 or 4. The installation documentation does seem to suggest it runs.

Nick
  • 776
  • 4
  • 15