title: PySide2 segfault in Qt main thread (0xC0000005)
body: <p><em>Windows 10. Currently using Python 3.10, PySide2/Qt 5.15.2.</em></p>
  <p>Our Python/PySide2 application (tested with PySide2 and PySide6 - official builds installed via pip) rarely and seemingly randomly segfaults in the Qt UI main thread.
  Running the Python interpeter in a debugger yielded the following information:</p>
  <ol>
  <li>The Qt thread will segfault in a different Qt library function every time</li>
  <li>All of these functions have the exact same assembly level structure:</li>
  </ol>
  <blockquote>
  <pre><code>mov qword ptr [rcx], 0
  mov rax, rcx
  </code></pre>
  </blockquote>
  <ol start="3">
  <li>The crashing instruction is always: mov qword ptr [rcx],0</li>
  <li>... because RCX is 0</li>
  </ol>
  <p>It's a rather massive data processing/visualization app with two entirely independent components (no data/code sharing at all). We're using openpyxl to parse excel sheets and pandas to manipulate data.</p>
  <p>The problem seems to occur primarily if, without exiting the programm, the visualization component has been used prior to the data processing.</p>
  <p>Segfaults will happen while running work (like applying changes to a pandas data frame) in a background thread eventhough the segfaulting thread is the Qt UI main thread.</p>
  <p>Using the Python faulthandler module, I've managed to extract approximate tracebacks from these background threads, but the traceback will look different almost every time:</p>
  <pre><code>Thread 0x00004504 (most recent call first):
    File &quot;pandas\core\dtypes\dtypes.py&quot;, line 974 in is_dtype
    File &quot;pandas\core\dtypes\common.py&quot;, line 456 in is_period_dtype
    File &quot;pandas\core\arrays\datetimelike.py&quot;, line 355 in _get_getitem_freq
    File &quot;pandas\core\arrays\datetimelike.py&quot;, line 348 in __getitem__
    File &quot;pandas\core\arrays\datetimes.py&quot;, line 629 in __iter__
    File &quot;pandas\core\apply.py&quot;, line 995 in series_generator
    File &quot;pandas\core\apply.py&quot;, line 865 in apply_series_generator
    File &quot;pandas\core\apply.py&quot;, line 851 in apply_standard
    File &quot;pandas\core\apply.py&quot;, line 727 in apply
    File &quot;pandas\core\frame.py&quot;, line 8839 in apply
    File &quot;essence\data_manager\model\cubes.py&quot;, line 443 in _create_cohort
    File &quot;essence\data_manager\model\cubes.py&quot;, line 91 in __init__
    File &quot;essence\data_manager\model\cube_manager.py&quot;, line 1454 in create_cubes
    File &quot;essence\data_manager\controller\worker.py&quot;, line 104 in _work
    File &quot;essence\data_manager\controller\worker.py&quot;, line 31 in work
    File &quot;threading.py&quot;, line 910 in run
    File &quot;threading.py&quot;, line 973 in _bootstrap_inner
    File &quot;threading.py&quot;, line 930 in _bootstrap
  
  
  
  Thread 0x00003f4c (most recent call first):
    File &quot;pandas\core\generic.py&quot;, line 5538 in __finalize__
    File &quot;pandas\core\frame.py&quot;, line 3915 in _box_col_values
    File &quot;pandas\core\frame.py&quot;, line 3442 in _ixs
    File &quot;pandas\core\frame.py&quot;, line 3932 in _get_item_cache
    File &quot;pandas\core\frame.py&quot;, line 3474 in __getitem__
    File &quot;pandas\core\groupby\grouper.py&quot;, line 873 in get_grouper
    File &quot;pandas\core\groupby\groupby.py&quot;, line 882 in __init__
    File &quot;pandas\core\frame.py&quot;, line 7712 in groupby
    File &quot;pandas\core\reshape\pivot.py&quot;, line 407 in _generate_marginal_results
    File &quot;pandas\core\reshape\pivot.py&quot;, line 292 in _add_margins
    File &quot;pandas\core\reshape\pivot.py&quot;, line 228 in __internal_pivot_table
    File &quot;pandas\core\reshape\pivot.py&quot;, line 95 in pivot_table
    File &quot;pandas\core\frame.py&quot;, line 8038 in pivot_table
    File &quot;essence\analysis_module\model\analyses\abstract_analysis.py&quot;, line 278 in pivot
    File &quot;essence\analysis_module\model\analyses\double_pivot.py&quot;, line 114 in create_singe_pivots
    File &quot;essence\analysis_module\model\analyses\double_pivot.py&quot;, line 94 in single_pivots
    File &quot;essence\analysis_module\model\analyses\double_pivot.py&quot;, line 182 in __init__
    File &quot;essence\analysis_module\model\model_abstract.py&quot;, line 348 in double_pivot
    File &quot;essence\analysis_module\model\model_abstract.py&quot;, line 335 in execute_analysis
    File &quot;essence\analysis_module\model\model_abstract.py&quot;, line 110 in create_analysis
    File &quot;essence\analysis_module\model\model_abstract.py&quot;, line 100 in update_analysis
    File &quot;essence\analysis_module\controller.py&quot;, line 82 in update_analysis
    File &quot;essence\ui\utils.py&quot;, line 37 in run
  
  
  
  Thread 0x00004254 (most recent call first):
    File &quot;xml\etree\ElementTree.py&quot;, line 1656 in _start
    File &quot;xml\etree\ElementTree.py&quot;, line 1722 in feed
    File &quot;xml\etree\ElementTree.py&quot;, line 1303 in feed
    File &quot;xml\etree\ElementTree.py&quot;, line 1265 in iterator
    File &quot;openpyxl\worksheet\_reader.py&quot;, line 144 in parse
    File &quot;openpyxl\worksheet\_read_only.py&quot;, line 79 in _cells_by_row
    File &quot;openpyxl\worksheet\worksheet.py&quot;, line 468 in values
    File &quot;essence\data_manager\model\file_loader.py&quot;, line 308 in &lt;listcomp&gt;
    File &quot;essence\data_manager\model\file_loader.py&quot;, line 308 in load_xlsx
    File &quot;essence\data_manager\model\file_loader.py&quot;, line 57 in load_preview
    File &quot;essence\data_manager\model\cube_manager.py&quot;, line 84 in load_preview
    File &quot;essence\ui\utils.py&quot;, line 37 in run
  
  
  
  Thread 0x000048fc (most recent call first):
    File &quot;threading.py&quot;, line 312 in wait
    File &quot;concurrent\futures\_base.py&quot;, line 441 in result
    File &quot;concurrent\futures\_base.py&quot;, line 609 in result_iterator
    File &quot;concurrent\futures\process.py&quot;, line 559 in _chain_from_iterable_of_lists
    File &quot;essence\data_manager\model\file_loader.py&quot;, line 357 in load_xlsx
    File &quot;essence\data_manager\model\file_loader.py&quot;, line 107 in load_full
    File &quot;essence\data_manager\model\cube_manager.py&quot;, line 98 in load_full
    File &quot;essence\data_manager\controller\worker.py&quot;, line 70 in _work
    File &quot;essence\data_manager\controller\worker.py&quot;, line 31 in work
    File &quot;threading.py&quot;, line 910 in run
    File &quot;threading.py&quot;, line 973 in _bootstrap_inner
    File &quot;threading.py&quot;, line 930 in _bootstrap
  
  
  
  Thread 0x00000b50 (most recent call first):
    File &quot;threading.py&quot;, line 833 in __init__
    File &quot;concurrent\futures\thread.py&quot;, line 194 in _adjust_thread_count
    File &quot;concurrent\futures\thread.py&quot;, line 176 in submit
    File &quot;pyarrow\pandas_compat.py&quot;, line 603 in dataframe_to_arrays
    File &quot;pandas\io\parquet.py&quot;, line 174 in write
    File &quot;pandas\io\parquet.py&quot;, line 420 in to_parquet
    File &quot;pandas\core\frame.py&quot;, line 2835 in to_parquet
    File &quot;pandas\util\_decorators.py&quot;, line 207 in wrapper
    File &quot;essence\project_file.py&quot;, line 446 in _serialize_df
    File &quot;essence\project_file.py&quot;, line 468 in _write
    File &quot;essence\project_file.py&quot;, line 463 in save_element
    File &quot;essence\data_manager\controller_datamanager.py&quot;, line 2003 in _work
    File &quot;essence\ui\utils.py&quot;, line 37 in run
  
  
  
  Thread 0x0000169c (most recent call first):
    File &quot;openpyxl\descriptors\base.py&quot;, line 143 in __set__
    File &quot;openpyxl\styles\alignment.py&quot;, line 49 in __init__
    File &quot;openpyxl\descriptors\serialisable.py&quot;, line 103 in from_tree
    File &quot;openpyxl\descriptors\serialisable.py&quot;, line 87 in from_tree
    File &quot;openpyxl\descriptors\serialisable.py&quot;, line 87 in from_tree
    File &quot;openpyxl\descriptors\serialisable.py&quot;, line 87 in from_tree
    File &quot;openpyxl\styles\stylesheet.py&quot;, line 103 in from_tree
    File &quot;openpyxl\styles\stylesheet.py&quot;, line 198 in apply_stylesheet
    File &quot;openpyxl\reader\excel.py&quot;, line 281 in read
    File &quot;openpyxl\reader\excel.py&quot;, line 317 in load_workbook
    File &quot;essence\data_manager\model\file_loader.py&quot;, line 295 in load_xlsx
    File &quot;essence\data_manager\model\file_loader.py&quot;, line 57 in load_preview
    File &quot;essence\data_manager\model\cube_manager.py&quot;, line 84 in load_preview
    File &quot;essence\ui\utils.py&quot;, line 37 in run
  </code></pre>
  <p>Every traceback is from a different runtime/process of the app.</p>
  <p>Based on how different they are, I've no idea how (if at all) the segfaulting Qt thread is related to the backend thread.</p>
  <p>Some threads will be started as a QRunnable in a ThreadPool, others are QThreads. Doesn't seem to be directly related to how a thread is started.</p>
  <p>I've since gone through different versions of thread management code without fixing the problem.</p>
  <p>The problem can not be reproduced reliably at all.</p>
  <p>Would appreciate litterally any insight, can provide minidumps/corefiles.</p>
  <hr />