Multiprocessing With kivy. A process in the process pool was terminated abruptly while the future was running or pending error

Question:

I have "A process in the process pool was terminated abruptly while the future was running or pending." error and I cant figure it out how to solve it. Pls Help me.
I have 2 program "proba.py" is the kivy program and "proba2.py" is the file_read program.

first program

# proba.py for kivy
from kivy.uix.widget import Widget
from kivy.app import App
import proba2

class Main(Widget):
    def __init__(self, **kwargs):
        super(Main, self).__init__(**kwargs)

    def Button(self):
        print ("W")
        proba2.File_read().Start()

class MainApp(App):

    def build(self):
        return Main()

if __name__ == '__main__':
    from kivy.lang import Builder

    Builder.load_string("""<Main>
    Button:
        on_press: root.Button()""")
    MainApp().run()

second program

# proba2.py for File_read
import concurrent.futures

class File_read():
    def __init__(self, **kwargs):
        super(File_read, self).__init__(**kwargs)

    def file_read (self, y, x):
        return y*x*self.Name  #Read files and give back to data

    def for_loop(self, Name):
        self.Name=Name
        results=[]
        results.clear()
        for_loop_result= []
        for_loop_result.clear()
        with concurrent.futures.ProcessPoolExecutor() as ex:
            for y in range (30):
                for x in range (30):
                    results.append (ex.submit(self.file_read,y,x))

            for f in concurrent.futures.as_completed(results):
                for_loop_result.append (f.result())
        return for_loop_result

    def Start(self):
        for Name_change in range (100):
            self.for_loop(Name_change)
            print ("Done")

"A process in the process pool was terminated abruptly while the future was running or pending."
This error stop my program but not immediately. Sometimes can finish the hole program some time stop in the middle of the loop.
I read about if name == ‘main‘ but cant use it when I call the other program with Button.
I mean I don’t know how to use it.
This program read 14k file and make a picture of them. When this program finish, I change the file name and want to start over the program for make more pictures.
This program is a short version because the original is too long. But the problem is same.
How can I make stable this program?

I work on windows 10 with python 3.10

Asked By: Bucsak

||

Answers:

I find the solution.
I take out the concurrent.futures from for cycle.

# proba2.py for File_read
import concurrent.futures
class File_read():
def __init__(self, **kwargs):
    super(File_read, self).__init__(**kwargs)

def file_read (self, y, x):
    return y*x*self.Name  #Read files and give back to data

def for_loop(self, Name):
    with concurrent.futures.ProcessPoolExecutor() as ex:
        for Name_change in range (100):
                self.Name=Name
                results=[]
                results.clear()
                for_loop_result= []
                for_loop_result.clear()
   
             for y in range (30):
                for x in range (30):
                   results.append (ex.submit(self.file_read,y,x))

                for f in concurrent.futures.as_completed(results):
                    for_loop_result.append (f.result())
        return for_loop_result

def Start():
    Name_change()
    print ("Done")
Answered By: Bucsak