forked from sampsyo/clusterfutures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
condor_example.py
37 lines (32 loc) · 1.03 KB
/
condor_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import cfut
import concurrent.futures
import subprocess
# "Worker" functions.
def square(n):
return n * n
def hostinfo():
return subprocess.check_output('hostname; uname -a', shell=True)
def example_1():
"""Square some numbers on remote hosts!
"""
with cfut.CondorExecutor(True) as executor:
futures = [executor.submit(square, n) for n in range(5)]
for future in concurrent.futures.as_completed(futures):
print(future.result())
def example_2():
"""Get host identifying information about the servers running
our jobs.
"""
with cfut.CondorExecutor(False) as executor:
futures = [executor.submit(hostinfo) for n in range(5)]
for future in concurrent.futures.as_completed(futures):
print(future.result().strip())
def example_3():
"""Demonstrates the use of the map() convenience function.
"""
exc = cfut.CondorExecutor(False)
print(list(cfut.map(exc, square, [5, 7, 11])))
if __name__ == '__main__':
example_1()
example_2()
example_3()