Created
June 6, 2019 08:13
-
-
Save dmitrysarov/5f6bf486f1c8e4b2af0ca92161d4ec90 to your computer and use it in GitHub Desktop.
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
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