Python sys.is_finalizing() Examples

The following are 15 code examples of sys.is_finalizing(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sys , or try the search function .
Example #1
Source File: test_sys.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def test_is_finalizing(self):
        self.assertIs(sys.is_finalizing(), False)
        # Don't use the atexit module because _Py_Finalizing is only set
        # after calling atexit callbacks
        code = """if 1:
            import sys

            class AtExit:
                is_finalizing = sys.is_finalizing
                print = print

                def __del__(self):
                    self.print(self.is_finalizing(), flush=True)

            # Keep a reference in the __main__ module namespace, so the
            # AtExit destructor will be called at Python exit
            ref = AtExit()
        """
        rc, stdout, stderr = assert_python_ok('-c', code)
        self.assertEqual(stdout.rstrip(), b'True') 
Example #2
Source File: test_sys.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def test_is_finalizing(self):
        self.assertIs(sys.is_finalizing(), False)
        # Don't use the atexit module because _Py_Finalizing is only set
        # after calling atexit callbacks
        code = """if 1:
            import sys

            class AtExit:
                is_finalizing = sys.is_finalizing
                print = print

                def __del__(self):
                    self.print(self.is_finalizing(), flush=True)

            # Keep a reference in the __main__ module namespace, so the
            # AtExit destructor will be called at Python exit
            ref = AtExit()
        """
        rc, stdout, stderr = assert_python_ok('-c', code)
        self.assertEqual(stdout.rstrip(), b'True') 
Example #3
Source File: util.py    From opendevops with GNU General Public License v3.0 5 votes vote down vote up
def _get_emulated_is_finalizing() -> Callable[[], bool]:
        L = []  # type: List[None]
        atexit.register(lambda: L.append(None))

        def is_finalizing() -> bool:
            # Not referencing any globals here
            return L != []

        return is_finalizing 
Example #4
Source File: util.py    From teleport with Apache License 2.0 5 votes vote down vote up
def _get_emulated_is_finalizing():
        L = []
        atexit.register(lambda: L.append(None))

        def is_finalizing():
            # Not referencing any globals here
            return L != []

        return is_finalizing 
Example #5
Source File: util.py    From teleport with Apache License 2.0 5 votes vote down vote up
def _get_emulated_is_finalizing() -> Callable[[], bool]:
        L = []  # type: List[None]
        atexit.register(lambda: L.append(None))

        def is_finalizing() -> bool:
            # Not referencing any globals here
            return L != []

        return is_finalizing 
Example #6
Source File: util.py    From teleport with Apache License 2.0 5 votes vote down vote up
def _get_emulated_is_finalizing() -> Callable[[], bool]:
        L = []  # type: List[None]
        atexit.register(lambda: L.append(None))

        def is_finalizing() -> bool:
            # Not referencing any globals here
            return L != []

        return is_finalizing 
Example #7
Source File: util.py    From pySINDy with MIT License 5 votes vote down vote up
def _get_emulated_is_finalizing():
        L = []
        atexit.register(lambda: L.append(None))

        def is_finalizing():
            # Not referencing any globals here
            return L != []

        return is_finalizing 
Example #8
Source File: unix_events.py    From Imogen with MIT License 5 votes vote down vote up
def close(self):
        super().close()
        if not sys.is_finalizing():
            for sig in list(self._signal_handlers):
                self.remove_signal_handler(sig)
        else:
            if self._signal_handlers:
                warnings.warn(f"Closing the loop {self!r} "
                              f"on interpreter shutdown "
                              f"stage, skipping signal handlers removal",
                              ResourceWarning,
                              source=self)
                self._signal_handlers.clear() 
Example #9
Source File: util.py    From enaml-native with MIT License 5 votes vote down vote up
def _get_emulated_is_finalizing():
        L = []
        atexit.register(lambda: L.append(None))

        def is_finalizing():
            # Not referencing any globals here
            return L != []

        return is_finalizing 
Example #10
Source File: client.py    From dask-gateway with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __del__(self):
        if (
            not self.asynchronous
            and hasattr(self, "_loop_runner")
            and not sys.is_finalizing()
        ):
            self.close() 
Example #11
Source File: client.py    From dask-gateway with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __del__(self):
        if not hasattr(self, "gateway"):
            return
        if self.asynchronous:
            # No del for async mode
            return
        if not sys.is_finalizing():
            self.close() 
Example #12
Source File: unix_events.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def close(self):
        super().close()
        if not sys.is_finalizing():
            for sig in list(self._signal_handlers):
                self.remove_signal_handler(sig)
        else:
            if self._signal_handlers:
                warnings.warn(f"Closing the loop {self!r} "
                              f"on interpreter shutdown "
                              f"stage, skipping signal handlers removal",
                              ResourceWarning,
                              source=self)
                self._signal_handlers.clear() 
Example #13
Source File: unix_events.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def close(self):
        super().close()
        if not sys.is_finalizing():
            for sig in list(self._signal_handlers):
                self.remove_signal_handler(sig)
        else:
            if self._signal_handlers:
                warnings.warn(f"Closing the loop {self!r} "
                              f"on interpreter shutdown "
                              f"stage, skipping signal handlers removal",
                              ResourceWarning,
                              source=self)
                self._signal_handlers.clear() 
Example #14
Source File: util.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def _get_emulated_is_finalizing() -> Callable[[], bool]:
        L = []  # type: List[None]
        atexit.register(lambda: L.append(None))

        def is_finalizing() -> bool:
            # Not referencing any globals here
            return L != []

        return is_finalizing 
Example #15
Source File: unix_events.py    From android_universal with MIT License 5 votes vote down vote up
def close(self):
        super().close()
        if not sys.is_finalizing():
            for sig in list(self._signal_handlers):
                self.remove_signal_handler(sig)
        else:
            if self._signal_handlers:
                warnings.warn(f"Closing the loop {self!r} "
                              f"on interpreter shutdown "
                              f"stage, skipping signal handlers removal",
                              ResourceWarning,
                              source=self)
                self._signal_handlers.clear()