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

Stop reactor gracefully on QApplication quit #2

Merged
merged 1 commit into from
Nov 5, 2015

Commits on Nov 4, 2015

  1. Stop reactor gracefully on QApplication quit

    If the reactor is running after the QApplication has quit, stop it and
    run all pending timed calls one last time. This will also allow the
    'shutdown' system event to trigger properly, which ReactorBase uses
    internally to stop its threadpool.
    
    Example:
    
    ```python
    from __future__ import print_function
    from sys import argv
    
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtCore import QTimer
    
    import qt5reactor
    
    if __name__ == '__main__':
        app = QApplication(argv)
    
        qt5reactor.install()
    
        from twisted.internet import reactor
    
        reactor.addSystemEventTrigger('before', 'shutdown', lambda: print('before'))
        reactor.addSystemEventTrigger('during', 'shutdown', lambda: print('during'))
        reactor.addSystemEventTrigger('after', 'shutdown', lambda: print('after'))
    
        QTimer.singleShot(1000, app.quit)  # Quit app after 1 second.
    
        reactor.run()
    ```
    
    Before, this would not print anything. After this change it will
    correctly print:
    
    before
    during
    after
    estan committed Nov 4, 2015
    Configuration menu
    Copy the full SHA
    d57a698 View commit details
    Browse the repository at this point in the history