ThreadPoolExecutor属性错误出现问题在主函数的while循环中的第一行“with concurrent.futures…”输入。这是我第一次深入研究这种线程方式,所以我不确定问题出在哪里
#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
目前没有回答
相关问题 更多 >
编程相关推荐