PySide6 App crashes randomly

Hi,
I’m currently developing a mid-sized app with Python + PySide6.
Unfortunately every time I start / debug the work in progress, everything seems to work normally:
I click on a treeView item → the corresponding tableView (that lists the data in the selected class instance) updates.
Do that between 10 and 300 times and the app will suddenly crash without any errors.

If I enable faulthandler, it points to a pandas related line of code (most of the times):

Windows fatal exception: access violation
[...]
Current thread 0x00001768 (most recent call first):
  Garbage-collecting
  File "c:\...\.venv\Lib\site-packages\pandas\core\flags.py", line 55 in __init__
  File "c:\...\.venv\Lib\site-packages\pandas\core\generic.py", line 279 in __init__
  File "c:\...\.venv\Lib\site-packages\pandas\core\generic.py", line 352 in _from_mgr
  File "c:\...\.venv\Lib\site-packages\pandas\core\frame.py", line 652 in _sliced_from_mgr
  File "c:\...\.venv\Lib\site-packages\pandas\core\frame.py", line 656 in _constructor_sliced_from_mgr
  File "c:\...\.venv\Lib\site-packages\pandas\core\frame.py", line 4392 in _box_col_values
  File "c:\...\.venv\Lib\site-packages\pandas\core\frame.py", line 3804 in _ixs
  File "c:\...\.venv\Lib\site-packages\pandas\core\frame.py", line 4002 in _get_value
  File "c:\...\.venv\Lib\site-packages\pandas\core\indexing.py", line 2440 in __getitem__
  File "c:\...\tools\mainwindow\models.py", line 146 in data
  File "c:\...\main_app.py", line 168 in init_mainwindow
  File "c:\...\start_app.py", line 11 in <module>
  File "c:\...\.vscode\extensions\ms-python.python-2023.21.13101009\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124 in _run_code

line 146 in models.py:

value = self.tab_dat.iat[index.row(), index.column()]

tab_dat is a DataFrame with a few rows.
More context:

class TableModelDBMainPage(QtCore.QAbstractTableModel):
    def __init__(self, tab_dat=pd.DataFrame(), parent=None):
        super(TableModelDBMainPage, self).__init__()
        self.tab_dat = tab_dat
        self.parent = parent
        self.colors = parent.colors

    def data(self, index, role):
        value = self.tab_dat.iat[index.row(), index.column()]
        attribute = self.tab_dat.columns[index.column()]
        if isinstance(value, datetime.datetime):
            value = datetime.datetime.strftime(value, "%d.%m.%Y - %H:%M")
[...]

tab_dat holds the data for the tableView model.
It is updated each time when the treeView is clicked.
That works, as mentioned, like 10-300 times before it crashes.
However, it’s not always pandas related, one time it crashed when loading in a dictionary…

More Info:

  • Python 3.11.4, Pandas 2.1.2, PySide6 6.6.0
  • I tried memory_profiler → as far as I can tell there is no memory leak (by looking at the graph)
  • no threading in app
  • I tried pdb instead of the vscode python debugger → also crashes after some time
  • I tried deleting the model data (DataFrame) each time before updating
  • rebuilt .venv from scratch
  • updated all dependecies

Does anyone have an idea or additional approaches?

Thank you.

Does the code work if you run it outside of vscode?
Try installing visual studio for c++ and running the app under it.
You can look at more details of the crash the visual stduio catches the
Access violation.

FYI access violation is not a memory leak.

You could also use PyQt6 instead and see if that works better.

I ran it outside of vscode → same behaviour.
I installed VS and ran the app → same behaviour. By now, i don’t get any more information, i “cranked” up the exception list, on what to stop the debugger (e.g. also Win32 Exceptions) but the debugger window doesn’t provide more information when crashing.
However, there is one error message popping up:
2023-11-07 11_45_55-IAC00194_Filterauslegung_Tool (wird ausgeführt) - Microsoft Visual Studio (Admin
(2nd line: “The value for Int32 was too big or small”)

I have no idea if this is related to my problem…
Sorry, its the first time using VS for me…

Using PyQt6 seems to be a very time-consuming process, because there are many lines of code to adapt.

Inside visual studio you can get it to show you the stack of C/C++ code that may help track the issue down.

If you are not C programmer this is going to be harder to debug.