0

I am developing a ToDo application in Python 3.13.1 with GUI in PyQt5 and connection to MySQL database via mysql-connector-python.

When I run main.py, the application instantly crashes (without even opening a window) with an error code:

Process finished with exit code -1073741819 (0xC0000005)

The error occurs on the very first line of the TasksData constructor, where mysql.connector.connect() is called:

cnx = mysql.connector.connect(user='...', database='...', password="...")

What's important:

  • The database is working correctly. If I run the tasks_data.py file separately, create a TasksData object and call methods - the connection to the database is successful and everything works as expected.

  • The crash appears only when running main.py (where the main window MainWindow is created and initialized, inside which TasksData is created). That is, the error occurs during initialization, even before the window is shown.

  • I wanted to display the error via try-except, but the program crashes immediately after the line with connection - the error does not have time to get to except, which probably indicates a problem with understanding what mysql it is accessing.

  • I've tried changing interpreters, recreating the virtual environment - I may have done some of these things wrong, but they didn't work.

  • Python version is 3.13.1

  • The path to the interpreter is correct: D:\PythonProjects\ToDoList.venv\Scripts\python.exe.

  • The mysql-connector-python==9.3.0 library is installed and shows up in the pip list inside the active venv.

  • I suspect the problem may be in the import, perhaps somehow other modules don't see the installed library or the wrong path is used. Although in a simple script everything works, inside PyQt5 it doesn't.

  • It could also be that mysql-connector-python doesn't quite work correctly with Python 3.13.1, but I haven't found any official confirmation.

Code for the error in turn, attached:

main.py

import sys
from PyQt5.QtWidgets import QApplication
from main_window import MainWindow

def main():
   app = QApplication(sys.argv)
   window = MainWindow()
   window.show()
   sys.exit(app.exec_())

if __name__ == '__main__':
   main()

main_window.py

from modules import main_window_builder
from tasks.tasks_data import TasksData
from windows.task_dialog import TaskDialog
from PyQt5.QtWidgets import *


class MainWindow(QMainWindow):

   def __init__(self):
       super().__init__()

       # -- Data
       try:
           self.tasks_data = TasksData()
       except Exception as e:
           print(f'[ERROR] {e}')

tasks_data.py

import mysql.connector
from tasks.task import Task


class TasksData:

   def __init__(self):
       # self.user = user(2, max, 123)
       self.task_items = self.get_data_from_db()

       self.completed_task_items = [tasks for tasks in self.task_items if tasks.is_done]
       self.uncompleted_task_items = [tasks for tasks in self.task_items if not tasks.is_done]

       self.task_lists = [self.task_items, self.completed_task_items, self.uncompleted_task_items]

   def insert_task(self, task_item):
       self.task_items.append(task_item)

       if task_item.task.is_done:
           self.completed_task_items.append(task_item)
       else:
           self.uncompleted_task_items.append(task_item)

   def get_data_from_db(self):
       cnx = mysql.connector.connect(user='...', database='...', password="...")

       cursor = cnx.cursor()

       query = ("select id, name, deadline, description, is_done from TASKS WHERE owner_id = %s")

       # id = user.id # get user id
       user_id = [1]

       cursor.execute(query, user_id)

       task_list = []

       for (id, name, deadline, description, is_done) in cursor:
           task = Task(id, name, deadline, description, is_done)
           task_list.append(task)

       cursor.close()
       cnx.close()

       for t in task_list:
           print(t.id, t.name, t.deadline, t.description, is_done)

       return task_list

if i create class object into tasks_data.py

run main.py

The interesting thing is that if earlier when I ran through Debug and I had some other error I was thrown to the parse.py file and displayed a specific error, this time it doesn't happen.

Question: Why does the application crashes when calling mysql.connector.connect() from within a PyQt5 application, although the module is installed and works correctly in separate runs? What could be the cause of error 0xC0000005 in this case?

6
  • post the complete error message and trace back as text not images Commented May 13 at 15:58
  • Printing the exception alone may not be enough. Leave out the try/except block and just create the instance, then run the code from a terminal or prompt: you should get the full traceback, which should be enough to tell you where the error could be, and if it isn't, then edit the post and add it as text, not images, as nbk noted above. A more comprehensive minimal reproducible example will also help, and you should also try to put the example in a single code block, instead of splitting it in 4 files, as it's unlikely that the reproducibility of the code would require it. Commented May 13 at 17:00
  • 1
    0xC0000005 is access violation error. As python is a managed memory language and you are using external libraries and apps, this is not a result in an error in your code but with some libraries / components you use. You need to narrow it down whether this is caused by your mysql connector, or by mysql itself. Commented May 13 at 17:38
  • Thanks guys for all the responses, I appreciate it! Tried to get more info with your tips, but I still fixed it thanks to the fact that I just installed mysql-connector-python from 9.3.0 to 8... Commented May 16 at 17:13
  • @панимаю Good for you, but right now your question cannot be answered, as it lacks enough details. The fact that downgrading solved the issue may just be a symptom of another problem that is currently impossible to understand (for instance, did you try to simply uninstall and reinstall the 9.3.0 version? did you try that code with a clean environment?). In its current form, this question is going to be closed soon (it already got 2 of 3 closure votes) and therefore deleted sooner or later, as we simply don't have enough context to understand where the problem may be. Commented May 17 at 20:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.