Here is a simple example. I am trying to find a maximum element in an incremented array which only contains positive integers. I want to let two algorithms run `find_max_1`

and `find_max_2`

in parallel, then the whole program terminates when one algorithm returns a result. Notice that the example stated here is just a **simplification** of the actual problem. In other words,it returns the fastest result and terminates the slower ones.

```
def find_max_1(array):
# method 1, just return the last element
return array(len(array)-1)
def find_max_2(array):
# method 2
solution = array(0);
for n in array:
solution = max(n, solution)
return solution
if __name__ == '__main__':
# Two algorithms run in parallel, when one returns a result, the whole program stop
pass
```

I hope I explained my question clearly and correctly. I find I can use `event`

and `terminate`

in `multiprocessing`

, all processes terminate when `event.is_set()`

is `true`

.

```
def find_max_1(array, event):
# method 1, just return the last element
event.set()
return array(len(array)-1)
def find_max_2(array, event):
# method 2
solution = array(0);
for n in array:
solution = max(n)
event.set()
return solution
if __name__ == '__main__':
# Two algorithms run in parallel, when one returns a result, the whole program stop
event = multiprocessing.Event()
array = (1, 2, 3, 4, 5, 6, 7, 8, 9... 1000000007)
p1 = multiprocessing.Process(target=find_max_1, args=(array, event,))
p2 = multiprocessing.Process(target=find_max_2, args=(array, event,))
jobs = (p1, p2)
p1.start()
p2.start()
p1.join()
p2.join()
while True:
if event.is_set():
for p in jobs:
p.terminate()
sys.exit(1)
time.sleep(2)
```

But not efficient. I wonder if two processes run **concurrently or in parallel** in the above method?

If there is a **better** implementation to solve it? Thank you very much!