Created
April 7, 2014 07:43
-
-
Save alejolp/10016215 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Alejandro Santos, @alejolp. | |
""" | |
This program deadlocks beacuse producers are also consumers and the Queue | |
has a fixed limit. When the consumer reaches a specific level on the expansion | |
tree, deadlocks. | |
""" | |
import os | |
import sys | |
import multiprocessing | |
import time | |
import random | |
q = multiprocessing.Queue(32) | |
def f(): | |
while True: | |
x = q.get() | |
time.sleep(random.randint(1,9) / 10.0) | |
print "Task:",x | |
for y in range(2): | |
q.put(2*x + y) | |
q.put(1) | |
procs = [multiprocessing.Process(target=f) for z in range(8)] | |
for p in procs: | |
p.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment