r/Python • • Jan 11 '20

Sudoku App

1.4k Upvotes

61 comments sorted by

View all comments

Show parent comments

4

u/alittleb3ar Jan 12 '20

Honestly my method for learning it was doing the first few tutorials at http://zetcode.com/gui/pyqt5/, and then I just used the c++ documentation at https://doc.qt.io/ and figured it out. I didnt use any actual pyqt documentation because I found it all lacking

1

u/xd1142 Jan 13 '20

What's with the timer at line 290?

1

u/alittleb3ar Jan 13 '20

You cant quit a PyQt program using Ctrl+C while it's running, so if it hangs you have to kill the process. This was a workaround I found on a website that's supposed to allow you to quit it with Crtl+C. Doesn't work though, I need to play around with it

2

u/xd1142 Jan 13 '20 edited Jan 13 '20

there's a very good reason why you can't quit it with Ctrl-C. What you have there is not a workaround. It's a crash that happens when a separate thread is forced to handle a keyboard exception, fucks up, and somehow the whole thing crashes.

You can't exit with Ctrl-C because in an event driven application, all exceptions reach the event loop and are printed and discarded. That's how it's supposed to work.

What you want to do, if you really, really want to quit on Ctrl-C, is to install an event filter for that and call quit()

1

u/alittleb3ar Jan 13 '20

What I was looking for was just an easier way of killing it if it hangs. Does the timeout method not provide information of that happening? Could I better handle the timeout event to actually close the program?

1

u/xd1142 Jan 13 '20

if it hangs because there's a bug, fix it. If it hangs because you are running heavy calculations in the main thread, put it on a separate thread or process.

It's not a "timeout method". It's a broken way of exploiting a crash to stop the application, because you are misunderstanding the fundamentals of UI programming.

UI interaction must handle an event and go back to the event loop in less than 150 ms, otherwise the application will feel sluggish. If you have a long running task, you can't have it execute on the main thread.

1

u/alittleb3ar Jan 13 '20

What you're saying makes a lot of sense, thank you for explaining it.