Created
April 9, 2022 04:42
-
-
Save Sc00bz/d856dff3d4cfe388daad831285fadc50 to your computer and use it in GitHub Desktop.
Broken Python: bytearray(), Process(), and Queue() don't like each other
This file contains 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
# Prints "done" 4 times then doesn't exit ~50% of the time. | |
from multiprocessing import Process, Queue | |
def f(q): | |
while 1: | |
try: | |
data = q.get(False) | |
except: | |
break | |
print("done") | |
if __name__ == '__main__': | |
q = Queue() | |
processes = [] | |
for i in range(10): | |
q.put(bytearray(13 * 65536)) | |
for i in range(4): | |
processes.append(Process(target=f, args=(q,))) | |
for p in processes: | |
p.start() | |
for p in processes: | |
p.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment