Last active
April 19, 2022 21:11
-
-
Save altendky/faf48446c335418dac8793635d119750 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qt5reactor | |
import sys | |
import time | |
import twisted | |
from PyQt5 import QtCore | |
def thread(): | |
print('threading') | |
time.sleep(1) | |
print('done threading') | |
def quit(): | |
print('quitting') | |
# TODO: _stopThreadPool() should not be necessary but otherwise | |
# it hangs on quit. Killing results in: | |
# | |
# Exception ignored in: <module 'threading' from '/usr/lib/python3.5/threading.py'> | |
# Traceback (most recent call last): | |
# File "/usr/lib/python3.5/threading.py", line 1288, in _shutdown | |
# t.join() | |
# File "/usr/lib/python3.5/threading.py", line 1054, in join | |
# self._wait_for_tstate_lock() | |
# File "/usr/lib/python3.5/threading.py", line 1070, in _wait_for_tstate_lock | |
# elif lock.acquire(block, timeout): | |
# KeyboardInterrupt | |
twisted.internet.reactor._stopThreadPool() | |
app.quit() | |
print('already quit') | |
app = QtCore.QCoreApplication(sys.argv) | |
qt5reactor.install() | |
# TODO: getThreadPool().start() should not be required but otherwise | |
# it hangs without running thread() | |
twisted.internet.reactor.getThreadPool().start() | |
d = twisted.internet.threads.deferToThread(thread) | |
d.addCallback(lambda _: quit()) | |
sys.exit(app.exec()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qt5reactor | |
import sys | |
import time | |
import twisted | |
from PyQt5 import QtCore | |
def thread(): | |
print('threading') | |
time.sleep(1) | |
print('done threading') | |
def quit(): | |
print('quitting') | |
app.quit() | |
print('already quit') | |
app = QtCore.QCoreApplication(sys.argv) | |
qt5reactor.install() | |
d = twisted.internet.threads.deferToThread(thread) | |
d.addCallback(lambda _: quit()) | |
import twisted.internet | |
sys.exit(twisted.internet.reactor.run()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
import twisted.internet | |
import twisted.internet.reactor | |
import twisted.internet.threads | |
def thread(): | |
print('threading') | |
time.sleep(1) | |
print('done threading') | |
def quit(): | |
print('quitting') | |
twisted.internet.reactor.stop() | |
print('already quit') | |
d = twisted.internet.threads.deferToThread(thread) | |
d.addCallback(lambda _: quit()) | |
sys.exit(twisted.internet.reactor.run()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replacing
sys.exit(app.exec())
with
sys.exit(twisted.internet.reactor.run())
works for me, and I can kill the application with CRTL-C, however my "quit" menu item no longer works - even when I define quit and link it to my thread. It seems to get stuck on a thread.join() call from my Qt window.