Skip to content

Instantly share code, notes, and snippets.

@alejolp
Created April 7, 2014 07:43
Show Gist options
  • Save alejolp/10016215 to your computer and use it in GitHub Desktop.
Save alejolp/10016215 to your computer and use it in GitHub Desktop.
#!/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