Skip to content

Commit

Permalink
Create parallelize.py
Browse files Browse the repository at this point in the history
  • Loading branch information
manmeet3591 authored May 8, 2021
1 parent 0d39873 commit adce0da
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions xarray_tutorial/parallelize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import time
import multiprocessing

def basic_func(x):
if x == 0:
return 'zero'
elif x%2 == 0:
return 'even'
else:
return 'odd'

def multiprocessing_func(x):
y = x*x
time.sleep(2)
print('{} squared results in a/an {} number'.format(x, basic_func(y)))

if __name__ == '__main__':
starttime = time.time()
processes = []
for i in range(0,10):
p = multiprocessing.Process(target=multiprocessing_func, args=(i,))
processes.append(p)
p.start()

for process in processes:
process.join()

print('That took {} seconds'.format(time.time() - starttime))

0 comments on commit adce0da

Please sign in to comment.