Skip to content

Instantly share code, notes, and snippets.

@ProfAndreaPollini
Created October 25, 2024 06:51
Show Gist options
  • Save ProfAndreaPollini/da994ec0ca93b433694485d72915af06 to your computer and use it in GitHub Desktop.
Save ProfAndreaPollini/da994ec0ca93b433694485d72915af06 to your computer and use it in GitHub Desktop.
Processi e Code 1
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