Skip to content

Instantly share code, notes, and snippets.

@kakarukeys
Created April 29, 2021 04:27
Show Gist options
  • Save kakarukeys/434222922356438bf77e83e229e738b7 to your computer and use it in GitHub Desktop.
Save kakarukeys/434222922356438bf77e83e229e738b7 to your computer and use it in GitHub Desktop.
Testing multi-processing processes
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