Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

Python ThreadpoolExecutor Attribute Error

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...