Having issues with ThreadPoolExecutor Attribute error enter at the first "with concurrent.futures..." line within while loop in the main function. This is my first dive into this way of threading so I'm not sure what the issue is.
#Sets up to 25 sectors as R or Y
def crop_dehydration(plot):
for _ in range(25):
x = random.randint(0,9)
y = random.randint(0,9)
if plot[x][y] != 'G':
plot[x][y].data = random.choice(hydration_choices)
#create irrigation logic
#Scans farm for R and Y sectors to add them to independent
#shceduled irrigation lists
def scan_farm(plot):
for i in range(10):
for j in range(10):
if plot[i][j] == 'R':
R.append(plot[i][j])
if plot[i][j] == 'Y':
Y.append(plot[i][j])
#handler for R and Y groups
def irrigate_sector(group, secs):
#irrigation handler for sectors within R and Y groups
def irrigate(sector, secs):
time.sleep(secs)
sector = 'G'
return sector
with concurrent.futures.ThreadPoolExecutor as executor:
results = {executor.submit(irrigate,sector, secs) for sector in group}
for i in concurrent.futures.as_completed(results):
return i.result()
def main():
farm = Sector()
while(True):
farm.display()
crop_dehydration(farm.plot)
scan_farm(farm.plot)
with concurrent.futures.ThreadPoolExecutor as executor:
r_thread = executor.submit(irrigate_sector, R, 25)
return r_thread.results()
with concurrent.futures.ThreadPoolExecutor as executor:
y_thread = executor.submit(irrigate_sector, Y, 10)
return y_thread.results()
main()
#create app initializer
#display gui
question from:
https://stackoverflow.com/questions/66057181/python-threadpoolexecutor-attribute-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…