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

# -*- coding: utf-8 -*-


import time 
from  threading import Thread, Lock

wallet = []
lock = Lock()
global obj 

def producer(obj):
    for i in range(10):
        obj = obj + i

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

    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.

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

  1. Write any program in python that does something, and does not produce errors when running. Take any beginner book. Get to know with functions, statements, classes, data structures.
  2. Google for "python threading tutorial". Read tutorials about threading. For example this link gives almost exactly what you want.
commented: wise advice +14

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 ?