summaryrefslogtreecommitdiff
path: root/python2/primes.py
diff options
context:
space:
mode:
Diffstat (limited to 'python2/primes.py')
-rw-r--r--python2/primes.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/python2/primes.py b/python2/primes.py
index 7e83ea0..ac684d6 100644
--- a/python2/primes.py
+++ b/python2/primes.py
@@ -23,22 +23,29 @@ def sequential():
return list(map(is_prime, PRIMES))
def with_process_pool_executor():
- with futures.ProcessPoolExecutor(10) as executor:
+ executor = futures.ProcessPoolExecutor(10)
+ try:
return list(executor.map(is_prime, PRIMES))
+ finally:
+ executor.shutdown()
def with_thread_pool_executor():
- with futures.ThreadPoolExecutor(10) as executor:
+ executor = futures.ThreadPoolExecutor(10)
+ try:
return list(executor.map(is_prime, PRIMES))
+ finally:
+ executor.shutdown()
def main():
for name, fn in [('sequential', sequential),
('processes', with_process_pool_executor),
('threads', with_thread_pool_executor)]:
- print('%s: ' % name.ljust(12), end='')
+ print '%s: ' % name.ljust(12),
+
start = time.time()
if fn() != [True] * len(PRIMES):
- print('failed')
+ print 'failed'
else:
- print('%.2f seconds' % (time.time() - start))
+ print '%.2f seconds' % (time.time() - start)
main() \ No newline at end of file