Created
May 5, 2020 09:54
-
-
Save soerenmartius/2ca34a2c9223116e7a0ae3f7081c3c29 to your computer and use it in GitHub Desktop.
Multiprocessing Example in Python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
def spawn_process(number): | |
print(f'Runs in separate process {number}') | |
if __name__ == '__main__': | |
max_processes = 5 | |
print(f'Start {max_processes} processes') | |
all_processes = [multiprocessing.Process(target=spawn_process, args=(i,)) for i in range(max_processes)] | |
for p in all_processes: | |
p.start() | |
for p in all_processes: | |
p.join() | |
print('Finished running all Processes') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment