Ребята, помогите исправить. Буду очень благодарен!!!
На 20-ой строчке пишет: «Redefining name ‘gs’ from outer scope(line 31)
import threading
import time
class GrainStore():
def __init__(self):
self.lock = threading.Lock()
self.grainLevel = 0
def add(self):
self.lock.acquire()
self.grainLevel += 1
print("Add: Grain Level = " + self.grainLevel)
self.lock.release()
def substract(self):
self.lock.acquire()
self.grainLevel -= 1
print("Substract: Grain Level = " + self.grainLevel)
self.lock.release()
class Farmer(threading.Thread):
def __init__(self, name, gs):
threading.Thread.__init__(self)
self.name = name
self.gs = gs
def run(self):
while(True):
#print("Hi")
gs.add()
time.sleep(3)
print("Farmer adding")
gs = GrainStore()
farmer1 = Farmer("Giles", gs)
farmer1.start()
#python #код #django #питон #джанго #программирование #cod #coding #ML #DataMining #deeplearning #neuralnets #neuralnetworks #neuralnetworks #ArtificialIntelligence #MachineLearning #DigitalTransformation #tech #ML #python
На 20-ой строчке пишет: «Redefining name ‘gs’ from outer scope(line 31)
import threading
import time
class GrainStore():
def __init__(self):
self.lock = threading.Lock()
self.grainLevel = 0
def add(self):
self.lock.acquire()
self.grainLevel += 1
print("Add: Grain Level = " + self.grainLevel)
self.lock.release()
def substract(self):
self.lock.acquire()
self.grainLevel -= 1
print("Substract: Grain Level = " + self.grainLevel)
self.lock.release()
class Farmer(threading.Thread):
def __init__(self, name, gs):
threading.Thread.__init__(self)
self.name = name
self.gs = gs
def run(self):
while(True):
#print("Hi")
gs.add()
time.sleep(3)
print("Farmer adding")
gs = GrainStore()
farmer1 = Farmer("Giles", gs)
farmer1.start()
#python #код #django #питон #джанго #программирование #cod #coding #ML #DataMining #deeplearning #neuralnets #neuralnetworks #neuralnetworks #ArtificialIntelligence #MachineLearning #DigitalTransformation #tech #ML #python
Ребята, помогите исправить. Буду очень благодарен!!!
На 20-ой строчке пишет: «Redefining name ‘gs’ from outer scope(line 31)
import threading
import time
class GrainStore():
def __init__(self):
self.lock = threading.Lock()
self.grainLevel = 0
def add(self):
self.lock.acquire()
self.grainLevel += 1
print("Add: Grain Level = " + self.grainLevel)
self.lock.release()
def substract(self):
self.lock.acquire()
self.grainLevel -= 1
print("Substract: Grain Level = " + self.grainLevel)
self.lock.release()
class Farmer(threading.Thread):
def __init__(self, name, gs):
threading.Thread.__init__(self)
self.name = name
self.gs = gs
def run(self):
while(True):
#print("Hi")
gs.add()
time.sleep(3)
print("Farmer adding")
gs = GrainStore()
farmer1 = Farmer("Giles", gs)
farmer1.start()
#python #код #django #питон #джанго #программирование #cod #coding #ML #DataMining #deeplearning #neuralnets #neuralnetworks #neuralnetworks #ArtificialIntelligence #MachineLearning #DigitalTransformation #tech #ML #python
На 20-ой строчке пишет: «Redefining name ‘gs’ from outer scope(line 31)
import threading
import time
class GrainStore():
def __init__(self):
self.lock = threading.Lock()
self.grainLevel = 0
def add(self):
self.lock.acquire()
self.grainLevel += 1
print("Add: Grain Level = " + self.grainLevel)
self.lock.release()
def substract(self):
self.lock.acquire()
self.grainLevel -= 1
print("Substract: Grain Level = " + self.grainLevel)
self.lock.release()
class Farmer(threading.Thread):
def __init__(self, name, gs):
threading.Thread.__init__(self)
self.name = name
self.gs = gs
def run(self):
while(True):
#print("Hi")
gs.add()
time.sleep(3)
print("Farmer adding")
gs = GrainStore()
farmer1 = Farmer("Giles", gs)
farmer1.start()
#python #код #django #питон #джанго #программирование #cod #coding #ML #DataMining #deeplearning #neuralnets #neuralnetworks #neuralnetworks #ArtificialIntelligence #MachineLearning #DigitalTransformation #tech #ML #python