Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle KeyboardInterrupt? Ctrl+C IOT instruction (core dumped). #127

Open
AI-Maria opened this issue Dec 2, 2024 · 0 comments
Open

Comments

@AI-Maria
Copy link

AI-Maria commented Dec 2, 2024

I want to shutdown when Ctrl+C is pressed.

from PyQt5.QtWidgets import QMainWindow, QSplitter, QPushButton
from PyQt5.QtCore import Qt
from qasync import QEventLoop, QApplication, asyncClose, asyncSlot
import sys
import asyncio

class MainWindow(QMainWindow):
    def __init__(self, app):
        self.app = app
        super().__init__()
        self.setWindowTitle("MainWindow")
        self.setGeometry(100, 100, 800, 600)
        splitter = QSplitter(Qt.Horizontal)
        self.setCentralWidget(splitter)
        send_button = QPushButton('button')
        splitter.addWidget(send_button)


    @asyncClose
    async def closeEvent(self, event):
        pass

    @asyncSlot()
    async def onMyEvent(self):
        pass

def main():
    app = QApplication(sys.argv)

    event_loop = QEventLoop(app)
    asyncio.set_event_loop(event_loop)

    app_close_event = asyncio.Event()
    app.aboutToQuit.connect(app_close_event.set)

    main_window = MainWindow(app)
    main_window.show()

    with event_loop:
        event_loop.run_until_complete(app_close_event.wait())

main()

python test.py
Press Ctrl+C and close button.

^CTraceback (most recent call last):
  File "/opt/miniconda3/envs/mar/lib/python3.11/site-packages/qasync/__init__.py", line 766, in wrapper
    @functools.wraps(fn)

KeyboardInterrupt
[1]    3160831 IOT instruction (core dumped)  python src/test.py

pyqt5 5.14.2
qasync 0.27.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant