Created
October 25, 2024 06:51
-
-
Save ProfAndreaPollini/da994ec0ca93b433694485d72915af06 to your computer and use it in GitHub Desktop.
Processi e Code 1
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 as mp | |
import time | |
import random | |
q = mp.Queue() | |
def producer(queue): | |
for _ in range(10): | |
time.sleep(1) | |
n = random.random() | |
queue.put(n) | |
task = mp.Process(target=producer, args=(q,)) | |
task.start() | |
while task.is_alive(): | |
try: | |
data = q.get(timeout=2) | |
except: | |
break | |
print(f"{data=}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment