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

#!/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    

You are very far from the solution.
Maybe you should try a much easier task first.

For example you have no working code. You create a wallet, a lock and a global variable and define two functions. You have a syntax error at line 4 because there is no right hand side value.

Edited 3 Years Ago by slate: x

Thanks for your reply. Can you please tell me what should i do to reach at the solution.

I agree with slate. You want a solution, but you didn't even describe the problem that you want to solve. Invoking the 'consumer producer problem' is far too abstract. Didn't you copy and paste code that you don't understand from the internet ?

This question has already been answered. Start a new discussion instead.