Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. An advice needed to catch Segmentation Violation
Qt 6.11 is out! See what's new in the release blog

An advice needed to catch Segmentation Violation

Scheduled Pinned Locked Moved Unsolved Qt for Python
10 Posts 2 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StarterKit
    wrote on last edited by StarterKit
    #1

    Hi all,
    I know that my question is not in a good form, but I'm lost with it for several months already so I decided to ask it as is.

    I have a python GUI application written with Qt. The problem happens in following way. User selects menu item and opens a child MDI window. This window contains QTableView that displays data from a model based on parameters selected by user. So, the user may select, for example, another date in QDateEdit or another item in a drop-down list from QComboBox. A change of these widgets triggers a slot that provides new parameters to the model - as result data in the model are changed and user see different numbers in the table.

    Everything works fine except one thing - sometimes the application crashes with Segmentation Violation after change of any parameter. It happens not often, for sure less then 5% of cases. It happens randomly - I can't reproduce the problem by repetition of the same sequence of actions (I tried many times in different scenario). It feels like some kind of race condition...
    I another similar MDI windows in my application (but they have a bit simpler models) - they never crashed, the problem happens only with one particular window. But I can't spot the difference to reduce the example for better debugging...

    So, as I suffer from this problem for a long time and ran out of ideas I decided to ask an advice of how to catch this problem or at least make a next step in this direction.

    JonBJ 1 Reply Last reply
    0
    • S StarterKit

      Hi all,
      I know that my question is not in a good form, but I'm lost with it for several months already so I decided to ask it as is.

      I have a python GUI application written with Qt. The problem happens in following way. User selects menu item and opens a child MDI window. This window contains QTableView that displays data from a model based on parameters selected by user. So, the user may select, for example, another date in QDateEdit or another item in a drop-down list from QComboBox. A change of these widgets triggers a slot that provides new parameters to the model - as result data in the model are changed and user see different numbers in the table.

      Everything works fine except one thing - sometimes the application crashes with Segmentation Violation after change of any parameter. It happens not often, for sure less then 5% of cases. It happens randomly - I can't reproduce the problem by repetition of the same sequence of actions (I tried many times in different scenario). It feels like some kind of race condition...
      I another similar MDI windows in my application (but they have a bit simpler models) - they never crashed, the problem happens only with one particular window. But I can't spot the difference to reduce the example for better debugging...

      So, as I suffer from this problem for a long time and ran out of ideas I decided to ask an advice of how to catch this problem or at least make a next step in this direction.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @StarterKit
      Nobody will be able to guess from the description. If it's "random", do you use threads anywhere in your code?

      First you should run under Python debugger. Do you get any stack trace when it seg faults? That may be untrappable from Python debugger. So then try running the actual Python executable with arguments (python3 myscript.py) under a C++ debugger (gdb, MSVC), what does its stack trace show when your Python crashes?

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @StarterKit
        Nobody will be able to guess from the description. If it's "random", do you use threads anywhere in your code?

        First you should run under Python debugger. Do you get any stack trace when it seg faults? That may be untrappable from Python debugger. So then try running the actual Python executable with arguments (python3 myscript.py) under a C++ debugger (gdb, MSVC), what does its stack trace show when your Python crashes?

        S Offline
        S Offline
        StarterKit
        wrote on last edited by
        #3

        @JonB,
        yes, I know that description is vague. I just understand that I reached the limits of my knowledge/experience and look for some new ideas what to try.

        No, I don't use threads in my application yet. I plan but with these kind of unresolved problems I don't think it is a wise move. So there might be some threads that Qt creates under the hood (to work with Camera for example) but from what I know this particular window has nothing to do and shouldn't be impacted by any thread operation.

        Frankly, I rarely ran gdb, so I haven't thought of its usage for python program. I'll try it and come back as soon as I catch something.

        JonBJ 1 Reply Last reply
        0
        • S StarterKit

          @JonB,
          yes, I know that description is vague. I just understand that I reached the limits of my knowledge/experience and look for some new ideas what to try.

          No, I don't use threads in my application yet. I plan but with these kind of unresolved problems I don't think it is a wise move. So there might be some threads that Qt creates under the hood (to work with Camera for example) but from what I know this particular window has nothing to do and shouldn't be impacted by any thread operation.

          Frankly, I rarely ran gdb, so I haven't thought of its usage for python program. I'll try it and come back as soon as I catch something.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @StarterKit First see what happens in Python debugger. Maybe that catches your seg fault? gdb after that, but that for sure won't show what in Python is causing crash, just maybe a clue from C++, but may not reveal much.

          S 1 Reply Last reply
          1
          • JonBJ JonB

            @StarterKit First see what happens in Python debugger. Maybe that catches your seg fault? gdb after that, but that for sure won't show what in Python is causing crash, just maybe a clue from C++, but may not reveal much.

            S Offline
            S Offline
            StarterKit
            wrote on last edited by StarterKit
            #5

            @JonB in python I see only Segmentation Violation and nothing else:
            Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)

            S 1 Reply Last reply
            0
            • S StarterKit

              @JonB in python I see only Segmentation Violation and nothing else:
              Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)

              S Offline
              S Offline
              StarterKit
              wrote on last edited by StarterKit
              #6

              I spent some time yesterday trying to reproduce the case but was not successful (but it failed a day before with the same code so I'm sure the problem was there...).
              This makes me a bit frustrated that I can't find a way how to reproduce it reliably.
              What I do:

              • I change GUI element that triggers a slot where model parameters are set.
              • As result model data are cleaned and new set of data is fetched.
              • Then modelReset is emitted to update QTreeView
              • expandAll() is called to expand everything.

              I use custom model and delegates derived from QStyledItemDelegate so I have 2 major suspects:

              • that my model might do something wrong or don't do something mandatory when I reset its content.
              • that delegate may be recreated in some not good moment.

              I passed my model to QAbstractItemModelTester and it found several problems with indices. I reviewed Qt examples and was able to fix these problems - so my model passes QAbstractItemModelTester successfully now.

              I'm not sure that it is a final fix as I was not able to reproduce the problem - I'll need some time to see has problem gone or not... So, I would be glad to hear what would be good to check additionally for the kind of use case that I described above.

              JonBJ 1 Reply Last reply
              0
              • S StarterKit

                I spent some time yesterday trying to reproduce the case but was not successful (but it failed a day before with the same code so I'm sure the problem was there...).
                This makes me a bit frustrated that I can't find a way how to reproduce it reliably.
                What I do:

                • I change GUI element that triggers a slot where model parameters are set.
                • As result model data are cleaned and new set of data is fetched.
                • Then modelReset is emitted to update QTreeView
                • expandAll() is called to expand everything.

                I use custom model and delegates derived from QStyledItemDelegate so I have 2 major suspects:

                • that my model might do something wrong or don't do something mandatory when I reset its content.
                • that delegate may be recreated in some not good moment.

                I passed my model to QAbstractItemModelTester and it found several problems with indices. I reviewed Qt examples and was able to fix these problems - so my model passes QAbstractItemModelTester successfully now.

                I'm not sure that it is a final fix as I was not able to reproduce the problem - I'll need some time to see has problem gone or not... So, I would be glad to hear what would be good to check additionally for the kind of use case that I described above.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @StarterKit
                Can't you at least put a whole bunch of print() statements in, or log to file, whatever, till you can find the last line executed from your Python script for seg fault? In an hour(?) you could isolate the line.

                S 1 Reply Last reply
                0
                • JonBJ JonB

                  @StarterKit
                  Can't you at least put a whole bunch of print() statements in, or log to file, whatever, till you can find the last line executed from your Python script for seg fault? In an hour(?) you could isolate the line.

                  S Offline
                  S Offline
                  StarterKit
                  wrote on last edited by
                  #8

                  @JonB, it seems this is the most viable strategy.
                  The main problem now - it happens quite rare - I can't reproduce it for last 2 days. So yes, I'll do a lot of prints - this way probably I'll find the line that triggers the crash... But it is for sure not an hour - hopefully a week. The problem happens after very simple action but I may do the same many times successfully and then, occasionally, it crashes. But I can't trigger it by myself :(

                  JonBJ 1 Reply Last reply
                  0
                  • S StarterKit

                    @JonB, it seems this is the most viable strategy.
                    The main problem now - it happens quite rare - I can't reproduce it for last 2 days. So yes, I'll do a lot of prints - this way probably I'll find the line that triggers the crash... But it is for sure not an hour - hopefully a week. The problem happens after very simple action but I may do the same many times successfully and then, occasionally, it crashes. But I can't trigger it by myself :(

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @StarterKit I meant an hour of putting in some print()/logging statements all over the place, then letting it run to reproduce in time.

                    S 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @StarterKit I meant an hour of putting in some print()/logging statements all over the place, then letting it run to reproduce in time.

                      S Offline
                      S Offline
                      StarterKit
                      wrote on last edited by
                      #10

                      @JonB said in An advice needed to catch Segmentation Violation:

                      @StarterKit I meant an hour of putting in some print()/logging statements all over the place, then letting it run to reproduce in time.

                      Oh... sorry, got it from second reading only. Agree with you.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved