Example #1
0
    def closeEvent(self, event):
        """ Override close event handler. """
        
        # Are we restaring?
        restarting = time.time() - self._closeflag < 1.0
        
        # Save settings
        pyzo.saveConfig()
        pyzo.command_history.save()
        
        # Stop command server
        commandline.stop_our_server()
        
        # Proceed with closing...
        result = pyzo.editors.closeAll()
        if not result:
            self._closeflag = False
            event.ignore()
            return
        else:
            self._closeflag = True
            #event.accept()  # Had to comment on Windows+py3.3 to prevent error
        
        # Proceed with closing shells
        pyzo.localKernelManager.terminateAll()
        for shell in pyzo.shells:
            shell._context.close()
        
        # Close tools
        for toolname in pyzo.toolManager.getLoadedTools():
            tool = pyzo.toolManager.getTool(toolname) 
            tool.close()
        
        # Stop all threads (this should really only be daemon threads)
        import threading
        for thread in threading.enumerate():
            if hasattr(thread, 'stop'):
                try:
                    thread.stop(0.1)
                except Exception:
                    pass
        
#         # Wait for threads to die ... 
#         # This should not be necessary, but I used it in the hope that it
#         # would prevent the segfault on Python3.3. It didn't.
#         timeout = time.time() + 0.5
#         while threading.activeCount() > 1 and time.time() < timeout:
#             time.sleep(0.1)
#         print('Number of threads alive:', threading.activeCount())
        
        # Proceed as normal
        QtWidgets.QMainWindow.closeEvent(self, event)
        
        # Harder exit to prevent segfault. Not really a solution,
        # but it does the job until Pyside gets fixed.
        if sys.version_info >= (3,3,0) and not restarting:
            if hasattr(os, '_exit'):
                os._exit(0)
Example #2
0
    def closeEvent(self, event):
        """Override close event handler."""

        # Are we restaring?
        restarting = time.time() - self._closeflag < 1.0  # noqa: F841

        # Save settings
        pyzo.saveConfig()
        pyzo.command_history.save()

        # Stop command server
        commandline.stop_our_server()

        # Proceed with closing...
        result = pyzo.editors.closeAll()
        if not result:
            self._closeflag = False
            event.ignore()
            return
        else:
            self._closeflag = True
            # event.accept()  # Had to comment on Windows+py3.3 to prevent error

        # Proceed with closing shells
        pyzo.localKernelManager.terminateAll()

        for shell in pyzo.shells:
            shell._context.close()

        # The tools need to be explicitly closed to allow them to clean up
        for toolname in pyzo.toolManager.getLoadedTools():
            tool = pyzo.toolManager.getTool(toolname)
            if hasattr(tool, "cleanUp"):
                tool.cleanUp()

        # Stop all threads (this should really only be daemon threads)
        import threading

        for thread in threading.enumerate():
            if hasattr(thread, "stop"):
                try:
                    thread.stop(0.1)
                except Exception:
                    pass

        #         # Wait for threads to die ...
        #         # This should not be necessary, but I used it in the hope that it
        #         # would prevent the segfault on Python3.3. It didn't.
        #         timeout = time.time() + 0.5
        #         while threading.activeCount() > 1 and time.time() < timeout:
        #             time.sleep(0.1)
        #         print('Number of threads alive:', threading.activeCount())

        # Proceed as normal
        QtWidgets.QMainWindow.closeEvent(self, event)
Example #3
0
        def closeEvent(self, event):
            '''
            A monkey-patched version of MainWindow.closeEvent.
            
            Copyright (C) 2013-2018, the Pyzo development team
            '''
            # pylint: disable=no-member, not-an-iterable
            # Pylint gets confused by monkey-patches.
            if g: g.pr('PATCHED MainWindow.closeEvent')

            # Are we restaring?
            # restarting = time.time() - self._closeflag < 1.0

            # Save settings
            pyzo.saveConfig()
            pyzo.command_history.save()

            # Stop command server
            commandline.stop_our_server()

            # Proceed with closing...
            result = pyzo.editors.closeAll()

            if 0:  # Force the close.
                if not result:
                    self._closeflag = False
                    event.ignore()
                    return
                self._closeflag = True

            # Proceed with closing shells
            pyzo.localKernelManager.terminateAll()

            for shell in pyzo.shells:
                shell._context.close()

            # Close tools
            for toolname in pyzo.toolManager.getLoadedTools():
                tool = pyzo.toolManager.getTool(toolname)
                tool.close()

            # Stop all threads (this should really only be daemon threads)
            import threading
            for thread in threading.enumerate():
                if hasattr(thread, 'stop'):
                    try:
                        thread.stop(0.1)
                    except Exception:
                        pass

            # Proceed as normal
            QtWidgets.QMainWindow.closeEvent(self, event)
Example #4
0
    def closeEvent(self, event):
        """ Override close event handler. """
        import pyzo.core.commandline as commandline

        g.pr('\nMainWindowShim.closeEvent 1')

        t1 = time.process_time()

        # Are we restaring?
        ### restarting = time.time() - self._closeflag < 1.0

        # Save settings
        pyzo.saveConfig()
        pyzo.command_history.save()

        # Stop command server
        commandline.stop_our_server()

        # Proceed with closing...
        result = pyzo.editors.closeAll()
        if not result:
            self._closeflag = False
            event.ignore()
            return
        else:
            self._closeflag = True

        t2 = time.process_time()

        # Proceed with closing shells
        pyzo.localKernelManager.terminateAll()  # pylint: disable=no-member
        for shell in pyzo.shells:
            shell._context.close()

        t3 = time.process_time()

        # Close tools
        for toolname in pyzo.toolManager.getLoadedTools():
            tool = pyzo.toolManager.getTool(toolname)
            tool.close()

        t4 = time.process_time()

        # Stop all threads (this should really only be daemon threads)
        import threading
        for thread in threading.enumerate():
            if hasattr(thread, 'stop'):
                try:
                    thread.stop(0.1)
                except Exception:
                    pass

        t5 = time.process_time()

        if 1:  # EKR
            g.pr('\nMainWindowShim.closeEvent 2')
            g.pr('stage 1:          %5.2f' % (t2 - t1))
            g.pr('stage 2: shells:  %5.2f' % (t3 - t2))
            g.pr('stage 3: tools:   %5.2f' % (t4 - t3))
            g.pr('stage 4: threads: %5.2f' % (t5 - t4))

        # Proceed as normal
        QtWidgets.QMainWindow.closeEvent(self, event)

        # Harder exit to prevent segfault. Not really a solution,
        # but it does the job until Pyside gets fixed.
        if sys.version_info >= (3, 3, 0):  # and not restarting:
            if hasattr(os, '_exit'):
                os._exit(0)
Example #5
0
def close_handler():  # pyzo_in_leo.py
    """
    Shut down pyzo.
    
    Called by Leo's shutdown logic when *all* outlines have been closed.
    
    This code is based on MainWindow.closeEvent.
    Copyright (C) 2013-2019 by Almar Klein.
    """

    print('\ng.app.pyzo_close_event\n')

    if 1:  # EKR: change

        def do_nothing(*args, **kwargs):
            pass

        # We must zero this out. pyzo.saveConfig calls this.
        pyzo.main.saveWindowState = do_nothing

    # EKR:change-new imports
    from pyzo.core import commandline

    # Are we restaring?
    # restarting = time.time() - self._closeflag < 1.0

    # EKR:change.
    if 1:  # As in the original.
        # Save settings
        pyzo.saveConfig()
        pyzo.command_history.save()

    # Stop command server
    commandline.stop_our_server()

    # Proceed with closing...
    pyzo.editors.closeAll()

    # EKR:change.
    # # Force the close.
    # if not result:
    # self._closeflag = False
    # event.ignore()
    # return
    # self._closeflag = True

    # Proceed with closing shells
    if 1:
        # pylint: disable=no-member
        pyzo.localKernelManager.terminateAll()

    for shell in pyzo.shells:
        shell._context.close()

    if 1:  # As in original.
        # Close tools
        for toolname in pyzo.toolManager.getLoadedTools():
            tool = pyzo.toolManager.getTool(toolname)
            tool.close()

    # Stop all threads (this should really only be daemon threads)
    # import threading
    for thread in threading.enumerate():
        if hasattr(thread, 'stop'):
            try:
                thread.stop(0.1)
            except Exception:
                pass