Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python3
from itertools import count
from math import sqrt
from concurrent.futures import ProcessPoolExecutor
def factory (x):
f = lambda k: 1.0/(k*(k+x))
return (f(k) for k in range(1, 1000000))
def psi (x):
return sum(factory(x))
with ProcessPoolExecutor(max_workers=4) as executor:
records = []
for x in (0.0, 0.5, 1.0, sqrt(2), 10.0, 100.0, 300.0):
worker = executor.submit(psi, x)
records.append((x, worker))
for x, future in records:
print("%6.2f , %16.12e" % (x, future.result()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment