Python Forum
When will the GIL be removed?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When will the GIL be removed?
#15
Many thanks, snippsat!

I've been able to reproduce the concurrent.futures.ProcessPoolExecutor example from the python manual.

import concurrent.futures
import math

PRIMES = [
    112272535095293,
    112582705942171,
    112272535095293,
    115280095190773,
    115797848077099,
    1099726899285419]

def is_prime(n):
   if n % 2 == 0:
       return False

   sqrt_n = int(math.floor(math.sqrt(n)))
   for i in range(3, sqrt_n + 1, 2):
       if n % i == 0:
           return False
   return True

def main():
   with concurrent.futures.ProcessPoolExecutor(max_workers= 2) as executor:
       for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)):
           print('%d is prime: %s' % (number, prime))

if __name__ == '__main__':
   main()
However, concurrent futures computing on 2 cores as shown above is NOT significantly faster than serial processing.

for i in range(0, len(PRIMES)):
print (PRIMES[i], is_prime(PRIMES[i]))
Thus, the big head from calling a process (which is only necessary because of the GIL) makes parallel computing in Python unattractive until the GIL is removed.

Quod erat demonstrandum.
Reply


Messages In This Thread
When will the GIL be removed? - by consuli - Nov-27-2016, 11:27 AM
RE: When will the GIL be removed? - by wavic - Nov-27-2016, 02:07 PM
RE: When will the GIL be removed? - by consuli - Nov-27-2016, 07:51 PM
RE: When will the GIL be removed? - by micseydel - Nov-27-2016, 10:00 PM
RE: When will the GIL be removed? - by consuli - Nov-28-2016, 06:47 PM
RE: When will the GIL be removed? - by wavic - Nov-28-2016, 08:54 AM
RE: When will the GIL be removed? - by micseydel - Nov-28-2016, 07:35 PM
RE: When will the GIL be removed? - by nilamo - Nov-28-2016, 08:01 PM
RE: When will the GIL be removed? - by pydsigner - Nov-29-2016, 04:58 PM
RE: When will the GIL be removed? - by snippsat - Nov-29-2016, 05:57 PM
RE: When will the GIL be removed? - by consuli - Nov-29-2016, 07:00 PM
RE: When will the GIL be removed? - by consuli - Dec-04-2016, 06:15 PM
RE: When will the GIL be removed? - by snippsat - Dec-04-2016, 06:33 PM
RE: When will the GIL be removed? - by snippsat - Dec-04-2016, 09:25 PM
RE: When will the GIL be removed? - by consuli - Dec-05-2016, 01:53 PM
RE: When will the GIL be removed? - by consuli - Dec-06-2016, 07:29 PM
RE: When will the GIL be removed? - by micseydel - Jan-06-2017, 12:22 AM
RE: When will the GIL be removed? - by nilamo - Jan-06-2017, 04:22 PM
RE: When will the GIL be removed? - by micseydel - Jan-06-2017, 06:32 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020