Skip to content

Instantly share code, notes, and snippets.

@dmitrysarov
Created June 6, 2019 08:13
Show Gist options
  • Save dmitrysarov/5f6bf486f1c8e4b2af0ca92161d4ec90 to your computer and use it in GitHub Desktop.
Save dmitrysarov/5f6bf486f1c8e4b2af0ca92161d4ec90 to your computer and use it in GitHub Desktop.
from multiprocessing import Process, Queue
from time import sleep
def loader(init_q, cache_q):
while not init_q.empty():
if cache_q.full():
continue
cache_q.put(init_q.get())
def predicter(init_q, cache_q):
while True:
sleep(1)
try:
print(cache_q.get(timeout=20))
except:
break
init_q = Queue()
for l in range(10):
init_q.put(l)
cache_q = Queue(2)
p = []
for _ in range(4):
p.append(Process(target=loader, args=(init_q, cache_q)))
for p_ in p:
p_.start()
predicter(init_q, cache_q)
for p_ in p:
p_.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment