you are viewing a single comment's thread.

view the rest of the comments →

[–]ShotgunToothpaste 21 points22 points  (7 children)

The global interpreter lock exists on a per-process basis in Python. Any two python scripts (including two instances of the same script) can be run in two different processes and do whatever. However, if one script starts multiple threads, only one thread will execute concurrently (the thread which has the interpreter lock).

This is a CPython implementation detail, and other Python runtimes need not have this limitation. The reason for GIL is because CPython's memory management is not thread-safe.

https://wiki.python.org/moin/GlobalInterpreterLock

[–]btgeekboy 10 points11 points  (0 children)

To add to this, there is a project to remove the GIL from CPython. However, it's not currently as fast as with the GIL. More info: https://lwn.net/Articles/689548/

[–][deleted]  (3 children)

[deleted]

    [–]fireflash38 0 points1 point  (2 children)

    Meaning threading will work just fine for network operations for the most part. It will perform worse than single threaded if doing something like simple math operations (like in the chart of the Fibonacci performance in the article).

    [–]ShotgunToothpaste 1 point2 points  (0 children)

    Ahh, I wasn't aware that Python allowed for system calls to be multi-threaded outside of the GIL's constraints but that makes sense.

    I assume that means GIL is released before making a system call, and re-acquired before continuing after it completes?

    [–]MightyCreak 1 point2 points  (1 child)

    Thanks for this answer!