Created
April 29, 2021 04:27
-
-
Save kakarukeys/434222922356438bf77e83e229e738b7 to your computer and use it in GitHub Desktop.
Testing multi-processing processes
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 time | |
import random | |
from multiprocessing import Process | |
def f(): | |
while True: | |
time.sleep(10) | |
dice = random.randint(1, 10) | |
if dice == 1: | |
raise ValueError | |
elif dice == 2: | |
break | |
if __name__ == "__main__": | |
print(1) | |
processes = [Process(target=f, daemon=False) for _ in range(20)] | |
print(2) | |
[p.start() for p in processes] | |
print(3) | |
[p.join() for p in processes] | |
print(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment