김동주
김동주

Reputation: 11

It runs, but 0xc0000409 error occurs during operation

I'm practicing a program that reads and displays Excel files Try raising the entire code. I'm using Python 3.9, Pycharm, PyQt5 - 5.15.7

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QTableWidget, QTableWidgetItem, QHeaderView, QHBoxLayout, QVBoxLayout, QPushButton
from PyQt5.QtCore import Qt
import pandas as pd
from pympler import muppy
all_objects = muppy.get_objects()

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.window_width, self.window_height = 700, 500
        self.resize(self.window_width, self.window_height)

        layout = QVBoxLayout()
        self.setLayout(layout)

        self.table = QTableWidget()
        layout.addWidget(self.table)

        self.button = QPushButton('&load Data')
        self.button.clicked.connect(lambda _, xl_path=excel_file_patch, sheet_name=worksheet_name: self.loadExcelData(xl_path, sheet_name))
        layout.addWidget(self.button)

    def loadExcelData(self, excel_file_dir, worksheet_name):
        df = pd.read_excel(excel_file_dir, worksheet_name)
        if df.size == 0:
            return super.loadExcelData(excel_file_dir, worksheet_name)

        df.fillna('', inplace=True)
        self.table.setRowCount(df.shape[0])
        self.table.setColumnCount(df.shape[0])
        self.table.setHorizontalHeaderLabels(df.columns)

if __name__ == '__main__':

    excel_file_patch = 'data.xlsx'
    worksheet_name = 'Sales'

    app = QApplication(sys.argv)
    myApp = MyApp()
    myApp.show()

    try:
        sys.exit(app.exec())
    except SystemExit:
        print('closing Window...')

Upvotes: 1

Views: 14452

Answers (1)

CyberHorns
CyberHorns

Reputation: 11

I encountered the same issue while working with a Tkinter-based application in Python 3.9 and Pycharm. The error 0xC0000409 appeared only when I was debugging and placed a breakpoint on super().__init__() during the initialization of a Tkinter window.

Instead of setting a breakpoint on super().__init__(), I moved the breakpoint just after the initialization. This way, the Tkinter event loop starts correctly, and the debugging proceeds without issues.

PS. I hope it will help someone to avoid 3 hours of trying to solve this (not)issue :P

Upvotes: 0

Related Questions