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

What is the proper way to launch the qt5reactor and QApplication? #12

Open
altendky opened this issue Jan 17, 2017 · 3 comments
Open

What is the proper way to launch the qt5reactor and QApplication? #12

altendky opened this issue Jan 17, 2017 · 3 comments

Comments

@altendky
Copy link
Member

I started using threads and ran into some issues. Turns out that while the reactor was 'working' for many things it wasn't getting started correctly and so deferToThread() didn't work and even when I started it up the application would then hang on exit.

What is the proper way to launch the qt5reactor and QApplication?

The readme covers installing the reactor in one of two ways but does not cover reactor.run() vs app.exec() or maybe something with reactor.runReturn() or...

My simple example for deferToThread() (both for qt5reactor and pure twisted) are available in this gist.

https://gist.github.com/altendky/faf48446c335418dac8793635d119750

@crwood
Copy link
Collaborator

crwood commented May 18, 2017

I don't know that there's a strictly "proper" method (since either method could work), however, reactor.run() is arguably the most straightforward of the two since, if I'm not mistaken, with QApplication.exec_() alone you would still have to start the reactor elsewhere in order to use the Twisted API (which largely defeats the primary purpose of the library -- i.e., to run/schedule both Qt and Twisted events within the same event-loop/thread).

My guess is that the reactor.runReturn() method described in the docstring is likely only intended for use-cases in which you might need to shutdown or restart the Twisted reactor for some reason while still keeping your Qt app running afterwards.

@altendky
Copy link
Member Author

Hmm, I tried lots of stuff but either something changed or I didn't try:

https://gist.github.com/altendky/faf48446c335418dac8793635d119750#file-qt5reactor_threads_run-py

Seems to work there and look kinda clean (even if my gut says Twisted should be subserviant to Qt :]). I'll give it a try in my real application as well as Windows (I'm in Linux most of the time).

@aalex
Copy link

aalex commented Sep 11, 2017

I think I get a similar issue on Windows. The Python script hangs after I close the window. Here is a ticket for it. #15

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

3 participants