Can Numba & Njit Work With a Python GUI Framework?

I am using a GUI framework called ‘FLET’ in python, but I was wondering why I keep getting the following error message:

numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
non-precise type pyobject
During: typing of argument at C:\Users\Aaron\Documents\Python\Project1\Table2.py (43)

File "Table2.py", line 43:
    def add_rows(self, e):
        self.lv.auto_scroll = True
        ^ 

This error may have been caused by the following argument(s):
- argument 0: Cannot determine Numba type of <class '__main__.Table'>
- argument 1: Cannot determine Numba type of <class 'flet_core.control_event.ControlEvent'>

Is there some other function that I’m supposed to be using inside of Numba other than ‘@njit’ on top of a function when using GUI frameworks?

I just have a simple for loop inside of a function that updates a GUI and tried sticking the ‘@njit’ on top of the function, then that’s when this error keeps popping up (as shown above). Thanks.

Oh, and here’s what the function looks like:

    @njit
    def add_rows(self, e):
        self.lv.auto_scroll = True
        self.lv.update()

        for i in range(1, 10001):
            self.count += 1
            self.dt.rows.append(
                ft.DataRow(
                    cells=[
                        ft.DataCell(ft.Text(f'# {self.count}')),
                        ft.DataCell(ft.Text(f'Keyword # 1')),
                        ft.DataCell(ft.Text(f'Keyword # 2')),
                        ft.DataCell(ft.Text(f'Keyword # 3')),
                        ft.DataCell(ft.Text(f'Keyword # 4')),
                    ]
                )
            )

            if i % 500 == 0:
                self.dt.update()
                self.lv.update()
                time.sleep(1.0)

        self.lv.auto_scroll = True
        self.lv.update()

        self.lv.auto_scroll = False
        self.lv.update()

Hi Aaron,

numba is not applicable to arbitrary python code. Its focus is on optimising computationally expensive low-level operations, particularly number-crunching.
It does not know how to deal with generic Python objects (efficiently). While there might be ways to use a compatibility mode, it would probably also destroy any performance benefits.

If you have some numerical heavy lifting to do in your app, isolate that code and it may well benefit from using numba, but there is probably not much to be gained by trying to make this work within GUI operations.

I have not worked with FLET but use PyQt5 a lot - usually populating UI views is not where you should find performance hits in the first place. If you have a data retrieval function written in Python that a view calls tens of thousands of times to render e.g. a table, then you could possibly struggle with bottlenecks.