Consumer Producer problem in python

This is the place for queries that don't fit in any of the other categories.

Consumer Producer problem in python

Postby vineet » Wed Sep 25, 2013 5:12 pm

I am writing a code of the consumer producer problem in python , so far I am almost ready but my code still not running.. Would you help me in any way to finish it, I am new in python and am not sure what I do wrong, any help is appreciated.

Kind regards
Vineet

Code: Select all
#!/usr/bin/python
# -*- coding: utf-8 -*-

__author__=



import time
from  threading import Thread, Lock

wallet = []
lock = Lock()
global obj

def producer(obj):
    lock.acquire()
    for i in range(10):
        obj = obj + i
        wallet.append(obj)
        time.sleep(1)
    lock.release()


def consumer():
    lock.acquire()
    for i in range(10):
        obj = obj - i
    obj = wallet.pop()
    lock.release()

    return obj   
Last edited by Yoriz on Wed Sep 25, 2013 6:52 pm, edited 1 time in total.
Reason: First post lock
vineet
 
Posts: 3
Joined: Wed Sep 25, 2013 5:09 pm

Re: Consumer Producer problem in python

Postby Yoriz » Wed Sep 25, 2013 6:56 pm

Hi welcome to the forum,
Please if you have not already, read the 'new users read this' link in my signature.

The first thing that is going to cause an error is that you have not assigned anything on the right side of the = in the following line.
Code: Select all
__author__=


You have created some functions but not called them at all so they won't do anything.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 789
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Consumer Producer problem in python

Postby vineet » Wed Sep 25, 2013 7:00 pm

Thanks for the reply. I am not sure what to pass in the producer function. Can you help me
vineet
 
Posts: 3
Joined: Wed Sep 25, 2013 5:09 pm

Re: Consumer Producer problem in python

Postby micseydel » Wed Sep 25, 2013 7:07 pm

What are you trying to do?
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1295
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Consumer Producer problem in python

Postby vineet » Wed Sep 25, 2013 7:10 pm

I want to implement the producer consumer problem using this code.
vineet
 
Posts: 3
Joined: Wed Sep 25, 2013 5:09 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 3 guests